Skip to content

Commit

Permalink
Ignore methods with type parameters in UseStaticImport (#3706)
Browse files Browse the repository at this point in the history
Fixes #3705.
  • Loading branch information
Bananeweizen authored Nov 19, 2023
1 parent 97bcf4f commit e908b09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Issue;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.test.RewriteTest;
Expand Down Expand Up @@ -73,6 +74,25 @@ void test() {
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/3705")
@Test
void ignoreMethodsWithTypeParameter() {
rewriteRun(
spec -> spec.recipe(new UseStaticImport("java.util.Collections emptyList()")),
java(
"""
import java.util.Collections;
import java.util.List;
public class Reproducer {
public void methodWithTypeParameter() {
List<Object> list = Collections.<Object>emptyList();
}
}
"""
)
);
}
@Test
void methodInvocationsHavingNullSelect() {
rewriteRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
MethodMatcher methodMatcher = new MethodMatcher(methodPattern);
J.MethodInvocation m = super.visitMethodInvocation(method, ctx);
if (methodMatcher.matches(m)) {
if (m.getTypeParameters() != null && !m.getTypeParameters().isEmpty()) {
return m;
}
if (m.getMethodType() != null) {
JavaType.FullyQualified receiverType = m.getMethodType().getDeclaringType();
maybeRemoveImport(receiverType);
Expand Down

0 comments on commit e908b09

Please sign in to comment.