diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 5354932c4201..55055c93b83c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1936,6 +1936,11 @@ public class HighlightUtil extends HighlightUtilBase { !thisOrSuperReference(((PsiReferenceExpression)expression).getQualifierExpression(), aClass)) { return null; } + + if (expression instanceof PsiJavaCodeReferenceElement && !aClass.equals(PsiTreeUtil.getParentOfType(expression, PsiClass.class))) { + return null; + } + final HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange()); if (expression instanceof PsiReferenceExpression && PsiUtil.isInnerClass(aClass)) { final String referenceName = ((PsiReferenceExpression)expression).getReferenceName(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java index fec91bc2dbb6..bafdc02117c7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java @@ -1,5 +1,7 @@ // reference before ctr called import java.io.*; +import java.lang.Override; +import java.lang.String; import java.net.*; class A { @@ -171,4 +173,32 @@ class WithAnonymous { } } +} + +class InnerClassRefInsideAnonymous { + static class Foo {} + static class SuperClass { + SuperClass(Foo foo) { + } + + SuperClass(String s, Foo foo) { + } + } + + static class Child extends SuperClass { + Child(Foo foo) { + super(new Foo() { + public String toString() { + AFoo afoo = null; + return super.toString(); + } + }); + } + + Child(String s, Foo foo) { + super(s, new AFoo()); + } + + class AFoo extends Foo {} + } } \ No newline at end of file