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
27 lines (23 loc) · 938 Bytes
/
MissingOverrideAnnotation.ql
File metadata and controls
27 lines (23 loc) · 938 Bytes
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
/**
* @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 maintainability
*/
import java
class OverridingMethod extends Method {
OverridingMethod() { exists(Method m | this.overrides(m)) }
predicate isOverrideAnnotated() { this.getAnAnnotation() instanceof OverrideAnnotation }
}
from OverridingMethod m, Method overridden
where
m.fromSource() and
m.overrides(overridden) and
not m.isOverrideAnnotated() and
not exists(FunctionalExpr mref | mref.asMethod() = m)
select m, "This method overrides $@; it is advisable to add an Override annotation.", overridden,
overridden.getDeclaringType() + "." + overridden.getName()