Make query more accepting

This commit is contained in:
Tamas Vajk
2025-03-07 10:56:17 +01:00
parent 4bf26afca0
commit 349f48982a
3 changed files with 12 additions and 16 deletions

View File

@@ -65,16 +65,6 @@ class SurefireTest extends Class {
}
}
/**
* Frameworks that provide `PointCuts`
* which commonly intentionally annotate empty methods
*/
class PointCutAnnotation extends Annotation {
PointCutAnnotation() {
this.getType().hasQualifiedName("org.aspectj.lang.annotation", "Pointcut")
}
}
/**
* A `Method` from source that is not abstract
*/
@@ -94,6 +84,10 @@ where
m.getNumberOfCommentLines() = 0 and
//permit a javadoc above as well as sufficient reason to leave empty
not exists(Javadoc jd | m.getDoc().getJavadoc() = jd) and
//methods annotated this way are usually intentionally empty
not exists(PointCutAnnotation a | a = m.getAnAnnotation())
//annotated methods are considered compliant
not exists(m.getAnAnnotation()) and
//default methods are not abstract, but are considered compliant
not m.isDefault() and
//native methods have no body
not m.isNative()
select m, "Empty method found."

View File

@@ -1,3 +1 @@
| Test.java:13:15:13:16 | f2 | Empty method found. |
| Test.java:27:17:27:17 | f | Empty method found. |
| Test.java:32:18:32:23 | method | Empty method found. |

View File

@@ -24,12 +24,16 @@ public class Test {
public class Derived extends TestInner {
@Override
public void f() { } // $ Alert
public void f() {
}
public native int nativeMethod();
}
public interface TestInterface {
default void method() { } // $ Alert
default void method() {
}
}
}