method reference: force constructor reference to be not exact if ClassType is raw

This commit is contained in:
Anna Kozlova
2015-02-16 17:24:15 +01:00
parent e3810e85b0
commit 0b40ad0cc7
2 changed files with 45 additions and 1 deletions
@@ -162,7 +162,27 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
LOG.assertTrue(componentType != null, qualifierResolveResult.getSubstitutor());
//15.13.1 A method reference expression of the form ArrayType :: new is always exact.
return factory.createMethodFromText("public " + componentType.createArrayType().getCanonicalText() + " __array__(int i) {return null;}", this);
} else {
}
else {
if (getQualifierType() == null) {
//ClassType is raw or is a non-static member type of a raw type.
PsiClass aClass = containingClass;
while (aClass != null) {
if (aClass.hasTypeParameters()) {
return null;
}
if (aClass.hasModifierProperty(PsiModifier.STATIC)) {
break;
}
aClass = aClass.getContainingClass();
if (PsiTreeUtil.isAncestor(aClass, this, true)) {
break;
}
}
}
methods = containingClass.getConstructors();
}
}
@@ -150,6 +150,30 @@ public class PsiPolyExpressionUtilTest extends LightCodeInsightFixtureTestCase {
assertFalse(InferenceSession.isPertinentToApplicability(psiExpression, meths[0]));
}
public void testNotExactMethodReferenceOnRawClassType() throws Exception {
myFixture.configureByText("Foo.java", "class Foo {" +
" class Test<A>{ Test(){}}" +
" {Runnable r = Test:<caret>:new;}" +
"}");
final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
final PsiExpression psiExpression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
assertInstanceOf(psiExpression, PsiMethodReferenceExpression.class);
assertFalse(((PsiMethodReferenceExpression)psiExpression).isExact());
}
public void testExactMethodReferenceOnGenericClassType() throws Exception {
myFixture.configureByText("Foo.java", "class Foo {" +
" class Test<A>{ Test(){}}" +
" {Runnable r = Test<String>:<caret>:new;}" +
"}");
final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
final PsiExpression psiExpression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
assertInstanceOf(psiExpression, PsiMethodReferenceExpression.class);
assertTrue(((PsiMethodReferenceExpression)psiExpression).isExact());
}
private boolean doTestLambdaPertinent(final String barText) {
myFixture.configureByText("Foo.java", "import java.util.*;" +
"class Foo {" +