mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-380311 [java-highlighting] Invalid code "cannot referenced from static context" not highlighted properly in Java
GitOrigin-RevId: e1d8918aca30a74ffbf3d3bbf8af07c6f45b5244
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2a900dd99d
commit
63e4043e5d
+5
-2
@@ -1668,9 +1668,12 @@ final class ExpressionChecker {
|
||||
PsiClass parentClass = constructor.getContainingClass();
|
||||
if (parentClass == null) return;
|
||||
|
||||
// references to private methods from the outer class are not calls to super methods
|
||||
// references to private methods and fields from the outer class are not calls to super methods
|
||||
// even if the outer class is the superclass
|
||||
if (resolved instanceof PsiMember member && member.hasModifierProperty(PsiModifier.PRIVATE) && referencedClass != parentClass) return;
|
||||
if (resolved instanceof PsiMember member && member.hasModifierProperty(PsiModifier.PRIVATE) &&
|
||||
referencedClass != parentClass && !(member instanceof PsiClass)) {
|
||||
return;
|
||||
}
|
||||
// field or method should be declared in this class or super
|
||||
if (!InheritanceUtil.isInheritorOrSelf(parentClass, referencedClass, true)) return;
|
||||
// and point to our instance
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
class A {
|
||||
A(C c) {}
|
||||
|
||||
static class B extends A {
|
||||
B() {
|
||||
super(new <error descr="Cannot reference 'C' before superclass constructor is called">C</error>());
|
||||
}
|
||||
|
||||
B(int x) {
|
||||
super(<error descr="Non-static method 'getC()' cannot be referenced from a static context">getC</error>());
|
||||
}
|
||||
|
||||
B(double x) {
|
||||
super(<error descr="Non-static field 'c' cannot be referenced from a static context">c</error>);
|
||||
}
|
||||
}
|
||||
|
||||
class B1 extends A {
|
||||
B1() {
|
||||
super(new <error descr="Cannot reference 'C' before superclass constructor is called">C</error>());
|
||||
}
|
||||
|
||||
B1(int x) {
|
||||
super(getC());
|
||||
}
|
||||
|
||||
B1(double x) {
|
||||
super(c);
|
||||
}
|
||||
}
|
||||
|
||||
private C getC() {
|
||||
return new C();
|
||||
}
|
||||
|
||||
private C c = new C();
|
||||
|
||||
private class C {}
|
||||
}
|
||||
+1
@@ -49,4 +49,5 @@ public class LightAdvHighlightingJdk8Test extends LightDaemonAnalyzerTestCase {
|
||||
doTest(true, true);
|
||||
}
|
||||
public void testCyclicInheritanceOfTypeAnnotation() { doTest(true, true); }
|
||||
public void testReferenceToPrivateClass() { doTest(true, true); }
|
||||
}
|
||||
Reference in New Issue
Block a user