Skip to content

Commit

Permalink
undo
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Potucek committed Dec 27, 2024
1 parent 04ec928 commit 140bbc6
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.Markers;

import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;

Expand All @@ -50,14 +47,16 @@
public class EqualsAvoidsNullVisitor<P> extends JavaVisitor<P> {

private static final String JAVA_LANG_STRING = "java.lang.String ";

private static final List<MethodMatcher> METHOD_MATCHERS = asList(
new MethodMatcher(JAVA_LANG_STRING + "equals(java.lang.Object)"),
new MethodMatcher(JAVA_LANG_STRING + "equalsIgnoreCase(java.lang.String)"),
new MethodMatcher(JAVA_LANG_STRING + "compareTo(java.lang.String)"),
new MethodMatcher(JAVA_LANG_STRING + "compareToIgnoreCase(java.lang.String)"),
new MethodMatcher(JAVA_LANG_STRING + "contentEquals(java.lang.CharSequence)")
);
private static final MethodMatcher EQUALS = new MethodMatcher(JAVA_LANG_STRING +
"equals(java.lang.Object)");
private static final MethodMatcher EQUALS_IGNORE_CASE = new MethodMatcher(JAVA_LANG_STRING +
"equalsIgnoreCase(java.lang.String)");
private static final MethodMatcher COMPARE_TO = new MethodMatcher(JAVA_LANG_STRING +
"compareTo(java.lang.String)");
private static final MethodMatcher COMPARE_TO_IGNORE_CASE = new MethodMatcher(JAVA_LANG_STRING +
"compareToIgnoreCase(java.lang.String)");
private static final MethodMatcher CONTENT_EQUALS = new MethodMatcher(JAVA_LANG_STRING +
"contentEquals(java.lang.CharSequence)");

EqualsAvoidsNullStyle style;

Expand Down Expand Up @@ -96,8 +95,12 @@ private boolean hasCompatibleArgument(J.MethodInvocation m) {
}

private boolean isStringComparisonMethod(J.MethodInvocation methodInvocation) {
return METHOD_MATCHERS.stream().anyMatch(matcher -> matcher.matches(methodInvocation))
&& !style.getIgnoreEqualsIgnoreCase();
return EQUALS.matches(methodInvocation) ||
!style.getIgnoreEqualsIgnoreCase() &&
EQUALS_IGNORE_CASE.matches(methodInvocation) ||
COMPARE_TO.matches(methodInvocation) ||
COMPARE_TO_IGNORE_CASE.matches(methodInvocation) ||
CONTENT_EQUALS.matches(methodInvocation);
}

private void maybeHandleParentBinary(J.MethodInvocation m) {
Expand Down

0 comments on commit 140bbc6

Please sign in to comment.