Skip to content

Commit

Permalink
IndexOfReplaceableByContainsTest: Fix error in recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Mar 14, 2024
1 parent 8007d4f commit 5dc62ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
J.Binary asBinary = (J.Binary) j;
if (asBinary.getLeft() instanceof J.MethodInvocation) {
J.MethodInvocation mi = (J.MethodInvocation) asBinary.getLeft();
if (STRING_INDEX_MATCHER.matches(mi) || LIST_INDEX_MATCHER.matches(mi)) {
if (STRING_INDEX_MATCHER.matches(mi) || mi.getSelect() != null && LIST_INDEX_MATCHER.matches(mi)) {
if (asBinary.getRight() instanceof J.Literal) {
String valueSource = ((J.Literal) asBinary.getRight()).getValueSource();
boolean isGreaterThanNegativeOne = asBinary.getOperator() == J.Binary.Type.GreaterThan && "-1".equals(valueSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,22 @@ static boolean hasIndex(List<String> strList, String str) {
)
);
}

@Test
void listIndexOfInImplementationClass() {
rewriteRun(
//language=java
java(
"""
import java.util.List;
abstract class Test implements List<String> {
boolean m(Object o) {
return indexOf(o) >= 0;
}
}
"""
)
);
}
}

0 comments on commit 5dc62ae

Please sign in to comment.