-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathPointlessForwardingMethod.ql
More file actions
55 lines (48 loc) · 1.5 KB
/
PointlessForwardingMethod.ql
File metadata and controls
55 lines (48 loc) · 1.5 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
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @name Pointless forwarding method
* @description A method forwards calls to another method of the same name that is not called independently.
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id cs/useless-forwarding-method
* @tags maintainability
* useless-code
*/
import csharp
predicate methodInClass(ValueOrRefType t, Method m, string name)
{
m.getDeclaringType() = t
and m.getName() = name
}
predicate callIn(MethodCall mc, Method fromMethod)
{
fromMethod = mc.getEnclosingCallable()
}
predicate callTo(MethodCall mc, Method toMethod)
{
toMethod = mc.getTarget().getSourceDeclaration()
}
predicate candidates(Method forwarder, Method forwardee)
{
exists(ValueOrRefType t, string name |
methodInClass(t, forwarder, name) and methodInClass(t, forwardee, name) |
not ignored(forwarder) and not ignored(forwardee) and forwarder != forwardee
)
}
predicate ignored(Method m)
{
m.isAbstract()
or m.implements()
or m.isOverride()
or m.isVirtual()
or m.getName() = "Dispose"
or not m.fromSource()
}
from Method forwarder, Method forwardee
where
not extractionIsStandalone()
and candidates(forwarder, forwardee)
and forex(MethodCall c | callTo(c, forwardee) | callIn(c, forwarder))
and forex(MethodCall c | callIn(c, forwarder) | callTo(c, forwardee))
select forwarder.getSourceDeclaration(), "This method is a forwarder for $@, which is not called independently - the methods can be merged.",
forwardee.getSourceDeclaration(), forwardee.getName()