accept this refs inside anonymous classes in java 8 interfaces (IDEA-105892)

This commit is contained in:
anna
2013-04-22 15:50:32 +02:00
parent 566ef9c3ab
commit 11f81e0be7
3 changed files with 33 additions and 1 deletions
@@ -1378,7 +1378,7 @@ public class HighlightUtil extends HighlightUtilBase {
if (expr instanceof PsiThisExpression) {
final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(expr, PsiMethod.class);
if (psiMethod == null || psiMethod.getContainingClass() != aClass) {
if (psiMethod == null || psiMethod.getContainingClass() != aClass && !isInsideDefaultMethod(psiMethod, aClass)) {
if (aClass.isInterface()) {
return thisNotFoundInInterfaceInfo(expr);
}
@@ -1393,6 +1393,13 @@ public class HighlightUtil extends HighlightUtilBase {
}
return null;
}
private static boolean isInsideDefaultMethod(PsiMethod method, PsiClass aClass) {
while (method != null && method.getContainingClass() != aClass) {
method = PsiTreeUtil.getParentOfType(method, PsiMethod.class, true);
}
return method != null && method.hasModifierProperty(PsiModifier.DEFAULT);
}
private static HighlightInfo thisNotFoundInInterfaceInfo(@NotNull PsiExpression expr) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expr).descriptionAndTooltip("Cannot find symbol variable this").create();
@@ -0,0 +1,24 @@
interface Bazz {
Bazz foo = <error descr="Cannot find symbol variable this">Bazz.this</error>;
static void foo1() {
Bazz foo = <error descr="'Bazz.this' cannot be referenced from a static context">Bazz.this</error>;
}
Runnable bar = new Runnable() {
@Override
public void run() {
Bazz f = <error descr="Cannot find symbol variable this">Bazz.this</error>;
}
};
default void foo() {
Bazz foo = Bazz.this;
Runnable r = new Runnable() {
@Override
public void run() {
Bazz f = Bazz.this;
}
};
}
}
@@ -29,6 +29,7 @@ public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCa
public void testInheritDefaultMethodInInterface() { doTest(false, false); }
public void testStaticMethodsInFunctionalInterface() { doTest(false, false); }
public void testCyclicSubstitutor() { doTest(false, false); }
public void testThisAccessibility() { doTest(false, false); }
private void doTest() {
doTest(false, false);