FN with ctor var shadowing

This commit is contained in:
Clément Fournier
2020-06-22 05:47:36 +02:00
parent 46ae538b18
commit 3a036c4933
3 changed files with 1456 additions and 1405 deletions

View File

@ -81,7 +81,7 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
* labels on arbitrary statements
* foreach var should be reassigned from one iter to another
* test local class/anonymous class
* test this.field in ctors
* explicit ctor call (hard to impossible without type res)
DONE
* conditionals
@ -92,6 +92,7 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
* lambdas
* constructors + initializers
* anon class
* test this.field in ctors
*/
@ -320,6 +321,12 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
// this is the normal finally
finalState = acceptOpt(finallyClause, finalState);
}
// In the 7.0 grammar, the resources should be explicitly
// used here. For now they don't trigger anything as their
// node is not a VariableDeclaratorId. There's a test to
// check that.
return finalState;
}
@ -964,6 +971,9 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
static class AssignmentEntry {
final VariableNameDeclaration var;
// this is not necessarily an expression, it may be also the
// variable declarator of a foreach loop
final JavaNode rhs;
AssignmentEntry(VariableNameDeclaration var, JavaNode rhs) {

View File

@ -141,12 +141,12 @@ public class VariableNameDeclaration extends AbstractNameDeclaration implements
return false;
}
VariableNameDeclaration n = (VariableNameDeclaration) o;
return n.node.getImage().equals(node.getImage());
return n.node.equals(this.node);
}
@Override
public int hashCode() {
return node.getImage().hashCode();
return node.hashCode();
}
@Override