Skip to content

Commit 349f489

Browse files
committed
Make query more accepting
1 parent 4bf26af commit 349f489

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

java/ql/src/Language Abuse/EmptyMethod.ql

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ class SurefireTest extends Class {
6565
}
6666
}
6767

68-
/**
69-
* Frameworks that provide `PointCuts`
70-
* which commonly intentionally annotate empty methods
71-
*/
72-
class PointCutAnnotation extends Annotation {
73-
PointCutAnnotation() {
74-
this.getType().hasQualifiedName("org.aspectj.lang.annotation", "Pointcut")
75-
}
76-
}
77-
7868
/**
7969
* A `Method` from source that is not abstract
8070
*/
@@ -94,6 +84,10 @@ where
9484
m.getNumberOfCommentLines() = 0 and
9585
//permit a javadoc above as well as sufficient reason to leave empty
9686
not exists(Javadoc jd | m.getDoc().getJavadoc() = jd) and
97-
//methods annotated this way are usually intentionally empty
98-
not exists(PointCutAnnotation a | a = m.getAnAnnotation())
87+
//annotated methods are considered compliant
88+
not exists(m.getAnAnnotation()) and
89+
//default methods are not abstract, but are considered compliant
90+
not m.isDefault() and
91+
//native methods have no body
92+
not m.isNative()
9993
select m, "Empty method found."
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
| Test.java:13:15:13:16 | f2 | Empty method found. |
2-
| Test.java:27:17:27:17 | f | Empty method found. |
3-
| Test.java:32:18:32:23 | method | Empty method found. |

java/ql/test/query-tests/EmptyMethod/Test.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ public abstract class TestInner {
2424
public class Derived extends TestInner {
2525

2626
@Override
27-
public void f() { } // $ Alert
27+
public void f() {
28+
}
29+
30+
public native int nativeMethod();
2831
}
2932

3033
public interface TestInterface {
3134

32-
default void method() { } // $ Alert
35+
default void method() {
36+
}
3337
}
3438

3539
}

0 commit comments

Comments
 (0)