File tree Expand file tree Collapse file tree
java/ql/src/Violations of Best Practice/Dead Code Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111import java
1212import DeadLocals
1313
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-
2214from LocalVariableDeclExpr ve , LocalVariableDecl v
2315where
2416 v = ve .getVariable ( ) and
2517 not assigned ( v ) and
2618 not read ( v ) and
2719 ( 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 .
2921 // Rules about catch clauses belong in an exception handling query
30- not exceptionVariable ( ve ) and
31- not enhancedForVariable ( ve )
22+ not ve .hasImplicitInit ( )
3223select v , "Variable " + v .getName ( ) + " is not used."
You can’t perform that action at this time.
0 commit comments