forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonOverridingMethod.ql
More file actions
43 lines (39 loc) · 1.28 KB
/
NonOverridingMethod.ql
File metadata and controls
43 lines (39 loc) · 1.28 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
33
34
35
36
37
38
39
40
41
42
43
/**
* @name Non-overriding method
* @description A method looks like it should override a virtual method from a base type, but does not actually do so.
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id cs/nonoverriding-method
* @tags reliability
* readability
* naming
*/
import csharp
private predicate potentialOverride(Method vm, Method m) {
vm.getDeclaringType() = m.getDeclaringType().getBaseClass+()
}
/**
* Holds if method `m` looks like it should override the virtual method `vm`,
* but does not do so.
*/
predicate nonOverridingMethod(Method m, Method vm) {
vm.isVirtual()
and not vm.isOverride()
and not vm.overrides()
and potentialOverride(vm, m)
and not m.overrides()
and not m.isOverride()
and not m.isNew()
and m=m.getSourceDeclaration()
and m.getNumberOfParameters() = vm.getNumberOfParameters()
and forall(int i, Parameter p1, Parameter p2 |
p1=m.getParameter(i) and p2=vm.getParameter(i) |
p1.getType() = p2.getType())
and m.getName().toLowerCase() = vm.getName().toLowerCase()
}
from Method m, Method vm
where m.fromSource()
and nonOverridingMethod(m, vm)
select m, "Method '" + m.getName() + "' looks like it should override $@ but does not do so.",
vm.getSourceDeclaration(), vm.getQualifiedName()