Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Dec 16, 2023
1 parent 9aa6fc4 commit d3ff0cc
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;

import java.util.HashMap;
Expand Down Expand Up @@ -75,20 +74,24 @@ class A {

@Test
void compareFieldAccess() {
assertExpressionsEqual("""
class A {
int n = 1;
int a = A.this.n;
int b = A.this.n;
}
""");
assertExpressionsEqual("""
class A {
int n = 1;
int a = A.this.n;
int b = this.n;
}
""");
assertExpressionsEqual(
"""
class A {
int n = 1;
int a = A.this.n;
int b = A.this.n;
}
"""
);
assertExpressionsEqual(
"""
class A {
int n = 1;
int a = A.this.n;
int b = this.n;
}
"""
);
}

private void assertEqualToSelf(@Language("java") String a) {
Expand Down Expand Up @@ -116,11 +119,11 @@ public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations
}
};

Map<String, J.VariableDeclarations.NamedVariable> result = new HashMap<>();
visitor.visit(cu, result);
Expression ea = result.get("a").getInitializer();
Expression eb = result.get("b").getInitializer();
assertEqual(Objects.requireNonNull(ea), Objects.requireNonNull(eb));
Map<String, J.VariableDeclarations.NamedVariable> result = visitor.reduce(cu, new HashMap<>());
assertEqual(
Objects.requireNonNull(result.get("a").getInitializer()),
Objects.requireNonNull(result.get("b").getInitializer())
);
}

private void assertEqual(J a, J b) {
Expand Down

0 comments on commit d3ff0cc

Please sign in to comment.