forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMissingOverrideAnnotation.ql
More file actions
32 lines (28 loc) · 1.09 KB
/
MissingOverrideAnnotation.ql
File metadata and controls
32 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @name Missing Override annotation
* @description A method that overrides a method in a superclass but does not have an 'Override'
* annotation cannot take advantage of compiler checks, and makes code less readable.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id java/missing-override-annotation
* @tags quality
* maintainability
* readability
*/
import java
class OverridingMethod extends Method {
OverridingMethod() { this.overrides(_) }
predicate isOverrideAnnotated() { this.getAnAnnotation() instanceof OverrideAnnotation }
}
from OverridingMethod m, Method overridden
where
m.fromSource() and
m.overrides(overridden) and
not m.hasModifier("override") and
not m.isOverrideAnnotated() and
not exists(FunctionalExpr mref | mref.asMethod() = m) and
// Ignore generated constructs, such as <clinit> functions extracted from Kotlin code:
not m.isCompilerGenerated()
select m, "This method overrides $@; it is advisable to add an Override annotation.", overridden,
overridden.getDeclaringType() + "." + overridden.getName()