mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method reference: force constructor reference to be not exact if ClassType is raw
This commit is contained in:
+21
-1
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -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 {" +
|
||||
|
||||
Reference in New Issue
Block a user