-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPointlessForwardingMethod.ql
More file actions
39 lines (35 loc) · 1.2 KB
/
PointlessForwardingMethod.ql
File metadata and controls
39 lines (35 loc) · 1.2 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
/**
* @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 low
* @id java/useless-forwarding-method
* @tags maintainability
*/
import java
predicate ignored(Method m) {
m.isAbstract() or
m.overrides(_)
}
Method forwarderCandidate(Method forwardee) {
result != forwardee and
result.getName() = forwardee.getName() and
result.getDeclaringType() = forwardee.getDeclaringType() and
forex(MethodAccess c | c.getMethod() = forwardee | c.getCaller() = result) and
forall(MethodAccess c | c.getCaller() = result | c.getMethod() = forwardee)
}
from Method forwarder, Method forwardee
where
forwarder = forwarderCandidate(forwardee) and
// Exclusions
not ignored(forwarder) and
not ignored(forwardee) and
not exists(VirtualMethodAccess c |
c.getMethod() = forwardee and
c.getCaller() = forwarder and
c.(MethodAccess).hasQualifier()
)
select forwarder.getSourceDeclaration(),
"This method is a forwarder for $@, which is not called independently - the methods can be merged.",
forwardee.getSourceDeclaration(), forwardee.getName()