Skip to content

Commit

Permalink
Update TypeMapping also check for Type.ForAll when building JavaTyp…
Browse files Browse the repository at this point in the history
…e.Method (#1176)
  • Loading branch information
pway99 authored Nov 4, 2021
1 parent 35bb53f commit 283158e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ public JavaType.Method methodType(@Nullable com.sun.tools.javac.code.Type select
}
}
}
} else if (selectType instanceof Type.ForAll) {
Type.ForAll fa = (Type.ForAll) selectType;
if (!fa.argtypes(false).isEmpty()) {
argumentTypeSignatures.add(fa.argtypes(false));
}
}

return typeCache.computeMethod(classfile(symbol.owner.type), signature(symbol.owner.type), methodName, signature(selectType.getReturnType()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ public JavaType.Method methodType(@Nullable com.sun.tools.javac.code.Type select
}
}
}
} else if (selectType instanceof Type.ForAll) {
Type.ForAll fa = (Type.ForAll) selectType;
if (!fa.argtypes(false).isEmpty()) {
argumentTypeSignatures.add(fa.argtypes(false));
}
}

return typeCache.computeMethod(classfile(symbol.owner.type), signature(symbol.owner.type), methodName, signature(selectType.getReturnType()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,55 @@ package org.openrewrite.java.search

import org.junit.jupiter.api.Test
import org.openrewrite.ExecutionContext
import org.openrewrite.Issue
import org.openrewrite.java.JavaParser
import org.openrewrite.java.JavaRecipeTest

@Suppress("RedundantOperationOnEmptyContainer")
interface UsesMethodTest : JavaRecipeTest {

@Issue("https://github.com/openrewrite/rewrite/issues/1169")
@Test
fun emptyConstructor(jp: JavaParser) = assertChanged(
jp,
recipe = toRecipe {
UsesMethod("abc.Thing newConcurrentHashSet()")
},
dependsOn = arrayOf(
"""
package abc;
import java.util.Set;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
public class Thing {
public static <E> Set<E> newConcurrentHashSet() {
return Collections.newSetFromMap(new ConcurrentHashMap<>());
}
public static <E> Set<E> newConcurrentHashSet(Iterable<? extends E> elements) {
return newConcurrentHashSet();
}
}
"""
),
before = """
package abc;
import java.util.Set;
class Test {
Set<String> s = Thing.newConcurrentHashSet();
}
""",
after = """
/*~~>*/package abc;
import java.util.Set;
class Test {
Set<String> s = Thing.newConcurrentHashSet();
}
"""
)

@Test
fun usesMethodReferences(jp: JavaParser) = assertChanged(
jp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,37 @@ package org.openrewrite.java.search

import org.junit.jupiter.api.Test
import org.openrewrite.ExecutionContext
import org.openrewrite.Issue
import org.openrewrite.java.JavaParser
import org.openrewrite.java.JavaRecipeTest

interface UsesTypeTest : JavaRecipeTest {

@Issue("https://github.com/openrewrite/rewrite/issues/1169")
@Test
fun emptyConstructor(jp: JavaParser) = assertChanged(
jp,
recipe = toRecipe {
UsesType<ExecutionContext>("java.util.ArrayList")
},
before = """
import java.util.ArrayList;
import java.util.List;
class Test {
List<String> l = new ArrayList<>();
}
""",
after = """
/*~~>*/import java.util.ArrayList;
import java.util.List;
class Test {
List<String> l = new ArrayList<>();
}
"""
)

@Test
fun usesTypeFindsImports(jp: JavaParser) = assertChanged(
jp,
Expand Down

0 comments on commit 283158e

Please sign in to comment.