constructor refs: decline abstract classes (IDEA-102392)

This commit is contained in:
anna
2013-03-04 16:03:07 +01:00
parent b2ab3ee6af
commit d7c5ecacdd
2 changed files with 16 additions and 3 deletions
@@ -267,6 +267,9 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
final PsiElement element = getReferenceNameElement();
final boolean isConstructor = element instanceof PsiKeyword && PsiKeyword.NEW.equals(element.getText());
if (element instanceof PsiIdentifier || isConstructor) {
if (isConstructor && (containingClass.isEnum() || containingClass.hasModifierProperty(PsiModifier.ABSTRACT))) {
return JavaResolveResult.EMPTY_ARRAY;
}
PsiType functionalInterfaceType = null;
final Map<PsiMethodReferenceExpression,PsiType> map = PsiMethodReferenceUtil.ourRefs.get();
if (map != null) {
@@ -289,9 +292,7 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
substitutor = LambdaUtil.inferFromReturnType(typeParameters, returnType, interfaceMethodReturnType, substitutor, languageLevel,
PsiMethodReferenceExpressionImpl.this.getProject());
if (containingClass.getConstructors().length == 0 &&
!containingClass.isEnum() &&
!containingClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (containingClass.getConstructors().length == 0) {
ClassCandidateInfo candidateInfo = null;
if ((containingClass.getContainingClass() == null || !isLocatedInStaticContext(containingClass)) && signature.getParameterTypes().length == 0 ||
PsiMethodReferenceUtil.onArrayType(containingClass, signature)) {
@@ -11,6 +11,14 @@ class Test {
static class Foo<X> { }
static abstract class ABar {
protected ABar() {
}
}
static abstract class ABaz {
}
void foo(IFactory cf) { }
void testAssign() {
@@ -19,11 +27,15 @@ class Test {
<error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c3 = I::new;</error>
IFactory c4 = Foo<?>::new;
IFactory c5 = <error descr="Cannot find class 1">1</error>::new;
<error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c6 = ABar::new;</error>
<error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c7 = ABaz::new;</error>
foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(Anno::new)</error>;
foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(E::new)</error>;
foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(I::new)</error>;
foo(Foo<?>::new);
foo(<error descr="Cannot find class 1">1</error>::new);
foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(ABar::new)</error>;
foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(ABaz::new)</error>;
}
}