-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathLocalShadowsFieldConfusing.ql
34 lines (32 loc) · 1.1 KB
/
LocalShadowsFieldConfusing.ql
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
/**
* @name Possible confusion of local and field
* @description A method in which a variable is declared with the same name as a field is difficult
* to understand.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id java/local-shadows-field
* @tags maintainability
* readability
*/
import java
import Shadowing
from LocalVariableDecl d, Class c, Field f, Callable callable, string callableType, string message
where
shadows(d, c, f, callable) and
not assignmentToShadowingLocal(d, f) and
not assignmentFromShadowingLocal(d, f) and
(if callable instanceof Constructor then callableType = "" else callableType = "method ") and
(
confusingAccess(d, f) and
message =
"Confusing name: " + callableType +
"$@ also refers to field $@ (without qualifying it with 'this')."
or
thisAccess(d, f) and
not confusingAccess(d, f) and
message =
"Potentially confusing name: " + callableType + "$@ also refers to field $@ (as this." +
f.getName() + ")."
)
select d, message, callable, callable.getName(), f, f.getName()