preserve captured wildcards during non wildcard parameterization (IDEA-132690)

This commit is contained in:
Anna Kozlova
2015-09-01 16:30:52 +03:00
parent 21e2fd41c0
commit ed06d3ff72
4 changed files with 28 additions and 2 deletions
@@ -477,6 +477,12 @@ public class GenericsUtil {
}
public static PsiType eliminateWildcards(PsiType type, final boolean eliminateInTypeArguments) {
return eliminateWildcards(type, eliminateInTypeArguments, !eliminateInTypeArguments);
}
public static PsiType eliminateWildcards(PsiType type,
final boolean eliminateInTypeArguments,
boolean eliminateCapturedWildcards) {
if (eliminateInTypeArguments && type instanceof PsiClassType) {
PsiClassType classType = (PsiClassType)type;
JavaResolveResult resolveResult = classType.resolveGenerics();
@@ -508,7 +514,8 @@ public class GenericsUtil {
else if (type instanceof PsiWildcardType) {
final PsiType bound = ((PsiWildcardType)type).getBound();
return eliminateWildcards(bound != null ? bound : ((PsiWildcardType)type).getExtendsBound(), false);//object
} else if (type instanceof PsiCapturedWildcardType && !eliminateInTypeArguments) {
}
else if (type instanceof PsiCapturedWildcardType && eliminateCapturedWildcards) {
return eliminateWildcards(((PsiCapturedWildcardType)type).getUpperBound(), false);
}
return type;
@@ -177,7 +177,7 @@ public class FunctionalInterfaceParameterizationUtil {
for (int i = 0; i < parameters.length; i++) {
PsiType paramType = parameters[i];
if (paramType instanceof PsiWildcardType) {
final PsiType bound = GenericsUtil.eliminateWildcards(((PsiWildcardType)paramType).getBound(), false);
final PsiType bound = GenericsUtil.eliminateWildcards(((PsiWildcardType)paramType).getBound(), false, false);
if (((PsiWildcardType)paramType).isSuper()) {
newParameters[i] = bound;
}
@@ -0,0 +1,15 @@
import java.util.concurrent.CompletableFuture;
interface Test {
CompletableFuture<?> doWork();
}
class Worker {
Test test;
public void stuff() {
test.doWork()
.exceptionally(t -> null);
}
}
@@ -212,6 +212,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testPreserveCapturedWildcardsDuringNonWildcardParameterization() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}