support captured types in incomplete overloaded lambda completion (IDEA-155188)

This commit is contained in:
peter
2016-04-26 10:23:35 +02:00
parent 1f94bd0419
commit 85601ec30c
3 changed files with 26 additions and 10 deletions
@@ -270,16 +270,9 @@ public class JavaCompletionUtil {
final int parameterIndex = lambdaExpression.getParameterList().getParameterIndex((PsiParameter)resolve);
final Set<LookupElement> set = new LinkedHashSet<LookupElement>();
final boolean overloadsFound = LambdaUtil.processParentOverloads(lambdaExpression, functionalInterfaceType -> {
PsiType qualifierType = LambdaUtil.getLambdaParameterFromType(functionalInterfaceType, parameterIndex);
PsiType qualifierType = removeTopLevelWildcards(LambdaUtil.getLambdaParameterFromType(functionalInterfaceType, parameterIndex));
if (qualifierType == null) return;
if (qualifierType instanceof PsiWildcardType) {
PsiType bound = ((PsiWildcardType)qualifierType).getBound();
if (bound != null) {
qualifierType = bound;
}
}
PsiReferenceExpression fakeRef = createReference("xxx.xxx", createContextWithXxxVariable(element, qualifierType));
set.addAll(processJavaQualifiedReference(fakeRef.getReferenceNameElement(), fakeRef, elementFilter, options, matcher, parameters));
});
@@ -288,10 +281,21 @@ public class JavaCompletionUtil {
}
}
}
}
}
return processJavaQualifiedReference(element, javaReference, elementFilter, options, matcher, parameters);
}
@Nullable
private static PsiType removeTopLevelWildcards(@Nullable PsiType qualifierType) {
if (qualifierType instanceof PsiCapturedWildcardType) {
return removeTopLevelWildcards(((PsiCapturedWildcardType)qualifierType).getWildcard());
}
if (qualifierType instanceof PsiWildcardType) {
return removeTopLevelWildcards(((PsiWildcardType)qualifierType).getBound());
}
return qualifierType;
}
private static Set<LookupElement> processJavaQualifiedReference(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter,
JavaCompletionProcessor.Options options,
final PrefixMatcher matcher, CompletionParameters parameters) {
@@ -0,0 +1,8 @@
import java.util.stream.*;
import java.util.*;
class Foo {
void main(Stream<? super String> stream) {
stream.collect(Collectors.toMap(o -> o.sub<caret>))
}
}
@@ -244,6 +244,10 @@ class Test88 {
configureByTestName()
myFixture.assertPreferredCompletionItems(0, 'substring', 'substring', 'subSequence')
}
public void testLambdaWithCapturedSuperWildcardInAmbiguousCall() {
configureByTestName()
myFixture.assertPreferredCompletionItems(0, 'substring', 'substring', 'subSequence')
}
public void testUnexpectedLambdaInAmbiguousCall() { doAntiTest() }
public void testNoCollectorsInComment() { doAntiTest() }