Skip to content

Commit

Permalink
Update src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.…
Browse files Browse the repository at this point in the history
…java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
punkratz312 and github-actions[bot] authored Feb 9, 2025
1 parent 32a7c73 commit d3abc1f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ public J visit(@Nullable Tree tree, ExecutionContext ctx) {
new MethodMatcher(JAVA_LANG_STRING + " equals(java.lang.Object)");
private final MethodMatcher EQUALS_IGNORE_CASE =
new MethodMatcher(JAVA_LANG_STRING + " equalsIgnoreCase(" + JAVA_LANG_STRING + ")");
private final MethodMatcher CONTENT_EQUALS = new MethodMatcher(JAVA_LANG_STRING
+ " contentEquals(java.lang.CharSequence)");

@Override
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext p) {
J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, p);
if (m.getSelect() != null
&& !(m.getSelect() instanceof J.Literal)
&& isStringComparisonMethod(m)
&& hasCompatibleArgument(m)) {
maybeHandleParentBinary(m, getCursor().getParentTreeCursor().getValue());
private final MethodMatcher CONTENT_EQUALS = new MethodMatcher(JAVA_LANG_STRING +
" contentEquals(java.lang.CharSequence)");
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, ctx);
if (m.getSelect() != null &&
!(m.getSelect() instanceof J.Literal) &&
isStringComparisonMethod(m) &&
hasCompatibleArgument(m)) {
return firstArgument.getType() == JavaType.Primitive.Null ?
literalsFirstInComparisonsNull(m, firstArgument) :
literalsFirstInComparisons(m, firstArgument);
Expression firstArgument = m.getArguments().get(0);
return firstArgument.getType() == JavaType.Primitive.Null
? literalsFirstInComparisonsNull(m, firstArgument)
Expand Down

0 comments on commit d3abc1f

Please sign in to comment.