mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
method refs: correct static flag detection in case of default constructors (IDEA-92735)
This commit is contained in:
@@ -300,10 +300,24 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
if (parameterTypes.length == 1 && LambdaUtil.isReceiverType(parameterTypes[0], containingClass, substitutor)) {
|
||||
hasReceiver = true;
|
||||
}
|
||||
if (parameterTypes.length == 0 || hasReceiver && !(containingClass.getContainingClass() == null || containingClass.hasModifierProperty(PsiModifier.STATIC))) {
|
||||
return new JavaResolveResult[]{new ClassCandidateInfo(containingClass, substitutor)};
|
||||
boolean insideStaticClass = containingClass.getContainingClass() == null;
|
||||
if (!insideStaticClass) { //inner class
|
||||
PsiClass parentClass = containingClass;
|
||||
while (parentClass != null) {
|
||||
if (parentClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
insideStaticClass = true;
|
||||
break;
|
||||
}
|
||||
|
||||
parentClass = parentClass.getContainingClass();
|
||||
}
|
||||
}
|
||||
return JavaResolveResult.EMPTY_ARRAY;
|
||||
final boolean innerClassOuterClassReference = containingClass.getContainingClass() != null && !containingClass.hasModifierProperty(PsiModifier.STATIC);
|
||||
ClassCandidateInfo candidateInfo = null;
|
||||
if (insideStaticClass && parameterTypes.length == 0 || hasReceiver && innerClassOuterClassReference) {
|
||||
candidateInfo = new ClassCandidateInfo(containingClass, substitutor);
|
||||
}
|
||||
return candidateInfo == null ? JavaResolveResult.EMPTY_ARRAY : new JavaResolveResult[]{candidateInfo};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,3 +56,33 @@ class DefaultConstructor2 {
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor2.I'">I i2 = this::new;</error>
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultConstructor3 {
|
||||
public class Inner {}
|
||||
public static class StaticInner {}
|
||||
|
||||
static <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor3.I'">I i = Inner::new;</error>
|
||||
static I1 i1 = StaticInner::new;
|
||||
interface I {
|
||||
Inner foo();
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
StaticInner foo();
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultConstructor4 {
|
||||
public class Inner {}
|
||||
public static class StaticInner {}
|
||||
|
||||
static I i = Inner::new;
|
||||
static <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor4.I1'">I1 i1 = StaticInner::new;</error>
|
||||
interface I {
|
||||
Inner foo(DefaultConstructor4 receiver);
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
StaticInner foo(DefaultConstructor4 receiver);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user