Skip to content

Commit

Permalink
Don't remove necessary whitespace in EqualsAvoidNull
Browse files Browse the repository at this point in the history
Fixes #434, but makes another test fail.
  • Loading branch information
Bananeweizen committed Jan 11, 2025
1 parent c72e0d2 commit dbd5628
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public RemoveUnnecessaryNullCheck(J.Binary scope) {
public J visitBinary(J.Binary binary, P p) {
if (scope.isScope(binary)) {
done = true;
return binary.getRight().withPrefix(Space.EMPTY);
return binary.getRight();
}
return super.visitBinary(binary, p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,33 @@ private boolean isBar(String bar) {
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/434")
void missingWhitespace() {
rewriteRun(
// language=java
java(
"""
class A {
private static final String FOO = "FOO";
boolean withParentExpression(String foo) {
return foo != null && foo.equals(FOO);
}
}
""",
"""
class A {
private static final String FOO = "FOO";
boolean withParentExpression(String foo) {
return FOO.equals(foo);
}
}
"""
)
);
}
}
}

0 comments on commit dbd5628

Please sign in to comment.