From 03ac96800c8319fa1e063d7a19ff4e32e5de5cd7 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 15 Nov 2012 12:02:26 +0100 Subject: [PATCH] this is inaccessible inside interface (IDEA-94986) --- .../daemon/impl/analysis/HighlightUtil.java | 16 ++++++++++++++++ .../advHighlighting/ThisInInterface.java | 8 ++++++++ .../daemon/LightAdvHighlightingTest.java | 1 + 3 files changed, 25 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java 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 021dc3790fd4..d05766095eb3 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 @@ -1305,9 +1305,25 @@ public class HighlightUtil extends HighlightUtilBase { return HighlightClassUtil.reportIllegalEnclosingUsage(expr, null, aClass, expr); } + if (expr instanceof PsiThisExpression && PsiTreeUtil.getParentOfType(expr, PsiMethod.class) == null) { + if (aClass.isInterface()) { + return thisNotFoundInInterfaceInfo(expr); + } + + if (aClass instanceof PsiAnonymousClass && PsiTreeUtil.isAncestor(((PsiAnonymousClass)aClass).getArgumentList(), expr, true)) { + final PsiClass parentClass = PsiTreeUtil.getParentOfType(aClass, PsiClass.class, true); + if (parentClass != null && parentClass.isInterface()) { + return thisNotFoundInInterfaceInfo(expr); + } + } + } return null; } + private static HighlightInfo thisNotFoundInInterfaceInfo(PsiExpression expr) { + return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expr, "Cannot find symbol variable this"); + } + private static boolean resolvesToImmediateSuperInterface(@NotNull PsiExpression expr, @Nullable PsiJavaCodeReferenceElement qualifier, @NotNull PsiClass aClass) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java new file mode 100644 index 000000000000..e32d0da7501c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ThisInInterface.java @@ -0,0 +1,8 @@ +class C implements A { + C(A a) {} +} + +interface A { + A a = new C(this); + A a1 = new C(this){}; +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index 646805fc7031..99b1ebcd6de2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -359,4 +359,5 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testUnsupportedFeatures() throws Exception { doTest(false, false); } public void testThisBeforeSuper() throws Exception { doTest(false, false); } public void testExplicitConstructorInvocation() throws Exception { doTest(false, false); } + public void testThisInInterface() throws Exception { doTest(false, false); } }