Skip to content

Commit

Permalink
Add fix (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlsanders4 authored Nov 15, 2024
1 parent 6f14b4c commit d84a33b
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ public TreeVisitor<?, ExecutionContext> getScanner(Set<JavaType.Variable> acc) {
@Override
public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations vd, ExecutionContext ctx) {
for (J.VariableDeclarations.NamedVariable variable : vd.getVariables()) {
checkForPropertiesVariable(variable.getVariableType(), variable.getInitializer());
Expression initializer = variable.getInitializer();
if (initializer != null) {
checkForPropertiesVariable(variable.getVariableType(), initializer);
}
}
return vd;
}

@Override
public J.Assignment visitAssignment(J.Assignment assignment, ExecutionContext ctx) {
JavaType.Variable variable = ((J.Identifier) assignment.getVariable()).getFieldType();
Expression assignmentVariable = assignment.getVariable();
if (!(assignmentVariable instanceof J.Identifier)) return assignment;
J.Identifier assignmentVariableIdentifier = (J.Identifier) assignmentVariable;
JavaType.Variable variable = assignmentVariableIdentifier.getFieldType();
if (!checkForPropertiesVariable(variable, assignment.getAssignment())) {
// If present, remove the variable from the accumulator since it was reassigned to an unrelated value
acc.remove(variable);
Expand Down

0 comments on commit d84a33b

Please sign in to comment.