File tree 1 file changed +2
-11
lines changed
java/ql/src/Violations of Best Practice/Dead Code
1 file changed +2
-11
lines changed Original file line number Diff line number Diff line change 11
11
import java
12
12
import DeadLocals
13
13
14
- predicate exceptionVariable ( LocalVariableDeclExpr ve ) {
15
- exists ( CatchClause catch | catch .getVariable ( ) = ve )
16
- }
17
-
18
- predicate enhancedForVariable ( LocalVariableDeclExpr ve ) {
19
- exists ( EnhancedForStmt for | for .getVariable ( ) = ve )
20
- }
21
-
22
14
from LocalVariableDeclExpr ve , LocalVariableDecl v
23
15
where
24
16
v = ve .getVariable ( ) and
25
17
not assigned ( v ) and
26
18
not read ( v ) and
27
19
( not exists ( ve .getInit ( ) ) or exprHasNoEffect ( ve .getInit ( ) ) ) and
28
- // Remove contexts where Java forces a variable declaration: enhanced-for and catch clauses.
20
+ // Remove contexts where Java forces a variable declaration: enhanced-for, catch clauses and pattern cases .
29
21
// Rules about catch clauses belong in an exception handling query
30
- not exceptionVariable ( ve ) and
31
- not enhancedForVariable ( ve )
22
+ not ve .hasImplicitInit ( )
32
23
select v , "Variable " + v .getName ( ) + " is not used."
You can’t perform that action at this time.
0 commit comments