mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
accept this refs inside anonymous classes in java 8 interfaces (IDEA-105892)
This commit is contained in:
@@ -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();
|
||||
|
||||
+24
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user