method refs: infer 'diamond' if constructor ref type is raw (IDEA-142142)

This commit is contained in:
Anna Kozlova
2015-07-02 20:08:10 +03:00
parent e98517a060
commit fe400fc988
3 changed files with 23 additions and 0 deletions
@@ -227,6 +227,19 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
psiSubstitutor = TypeConversionUtil.getClassSubstitutor(qContainingClass, paramClass, resolveResult.getSubstitutor());
LOG.assertTrue(psiSubstitutor != null);
}
else if (member instanceof PsiMethod && ((PsiMethod)member).isConstructor() || member instanceof PsiClass) {
//15.13.1
//If ClassType is a raw type, but is not a non-static member type of a raw type,
//the candidate notional member methods are those specified in §15.9.3 for a class instance creation expression that uses <>
//to elide the type arguments to a class.
final PsiResolveHelper helper = JavaPsiFacade.getInstance(myExpression.getProject()).getResolveHelper();
final PsiType[] paramTypes =
member instanceof PsiMethod ? ((PsiMethod)member).getSignature(PsiSubstitutor.EMPTY).getParameterTypes() : PsiType.EMPTY_ARRAY;
psiSubstitutor = helper.inferTypeArguments(qContainingClass.getTypeParameters(),
paramTypes,
signature.getParameterTypes(),
PsiUtil.getLanguageLevel(myExpression));
}
else {
psiSubstitutor = PsiSubstitutor.EMPTY;
}
@@ -0,0 +1,6 @@
import java.util.*;
class Test {
public Optional<Set<String>> foo(Optional<Set<String>> args) {
return args.map(HashSet::new).map(Collections::unmodifiableSet);
}
}
@@ -414,6 +414,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testRawClassTypeOnConstructorReference() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}