this is inaccessible inside interface (IDEA-94986)

This commit is contained in:
anna
2012-11-15 12:52:26 +01:00
parent d9d8e546dd
commit 03ac96800c
3 changed files with 25 additions and 0 deletions
@@ -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) {
@@ -0,0 +1,8 @@
class C implements A {
C(A a) {}
}
interface A {
A a = new C(<error descr="Cannot find symbol variable this">this</error>);
A a1 = new C(<error descr="Cannot find symbol variable this">this</error>){};
}
@@ -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); }
}