From ed86103b09041d76add7d1a23078475ff98af120 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 23 Apr 2020 16:24:18 +0700 Subject: [PATCH] Removing redundant code (IDEA-CR-61866) Actually covered by other branches GitOrigin-RevId: 6f8a400d4d6160f2ec7e198d8fbf0119e9d1c84c --- .../daemon/impl/analysis/HighlightUtil.java | 28 ------------------- .../src/messages/JavaErrorBundle.properties | 1 - .../PrivateInInterfacesAnonymousThis.java | 18 ++++++++++++ 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 79e52a19c412..042216c2a01c 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1728,22 +1728,6 @@ public class HighlightUtil { } } } - - if (expr instanceof PsiThisExpression) { - final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(expr, PsiMethod.class); - if (psiMethod == null || psiMethod.getContainingClass() != aClass) { - if (aClass.isInterface() && !isInsideInterfaceInstanceMethod(psiMethod, aClass)) { - 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; } @@ -1762,18 +1746,6 @@ public class HighlightUtil { return null; } - private static boolean isInsideInterfaceInstanceMethod(@NotNull PsiMethod method, @NotNull PsiClass aClass) { - while (method != null && method.getContainingClass() != aClass) { - method = PsiTreeUtil.getParentOfType(method, PsiMethod.class, true); - } - return method != null && !method.hasModifierProperty(PsiModifier.STATIC); - } - - private static HighlightInfo thisNotFoundInInterfaceInfo(@NotNull PsiExpression expr) { - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expr).descriptionAndTooltip( - JavaErrorBundle.message("error.no.enclosing.this.in.interface")).create(); - } - private static boolean resolvesToImmediateSuperInterface(@NotNull PsiExpression expr, @Nullable PsiJavaCodeReferenceElement qualifier, @NotNull PsiClass aClass, diff --git a/java/java-psi-impl/src/messages/JavaErrorBundle.properties b/java/java-psi-impl/src/messages/JavaErrorBundle.properties index 772667f1d5fe..7065bbc5323b 100644 --- a/java/java-psi-impl/src/messages/JavaErrorBundle.properties +++ b/java/java-psi-impl/src/messages/JavaErrorBundle.properties @@ -459,4 +459,3 @@ abstract.method.0.cannot.be.accessed.directly.method.reference.context=Abstract error.interface.member.clashes=@interface member clashes with ''{0}'' in {1} anonymous.class.implements.interface.cannot.have.type.arguments=Anonymous class implements interface; cannot have type arguments formal.varargs.element.type.inaccessible.here=Formal varargs element type {0} is inaccessible here -error.no.enclosing.this.in.interface=Cannot find symbol variable this \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting9/PrivateInInterfacesAnonymousThis.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting9/PrivateInInterfacesAnonymousThis.java index 06c84652da68..d8a653e13a15 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting9/PrivateInInterfacesAnonymousThis.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting9/PrivateInInterfacesAnonymousThis.java @@ -7,4 +7,22 @@ interface Foo { } }; } + default void bar1() { + new Runnable() { + @Override + public void run() { + System.out.println(Foo.this); + } + }; + } + static void bar2() { + new Runnable() { + @Override + public void run() { + System.out.println(Foo.this); + } + }; + } + int getX(); + int x = this.getX(); }