check access class for super expressions referenced to interfaces

This commit is contained in:
Anna Kozlova
2014-04-09 19:24:44 +02:00
parent ef82d76864
commit 5a0fe4306e
3 changed files with 42 additions and 4 deletions

View File

@@ -439,9 +439,15 @@ public class PsiScopesUtil {
}
else if (resolve instanceof PsiClass) {
PsiExpression qualifier = methodCall.getMethodExpression().getQualifierExpression();
if (!(qualifier instanceof PsiSuperExpression) || ((PsiSuperExpression)qualifier).getQualifier() != null && PsiUtil.isLanguageLevel8OrHigher(methodCall)) {
if (!(qualifier instanceof PsiSuperExpression)) {
processor.setAccessClass((PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement());
}
else if (((PsiSuperExpression)qualifier).getQualifier() != null && PsiUtil.isLanguageLevel8OrHigher(qualifier)) {
final PsiClass accessClass = (PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement();
if (accessClass != null && accessClass.isInterface()) {
processor.setAccessClass(accessClass);
}
}
}
processor.setIsConstructor(false);

View File

@@ -0,0 +1,9 @@
package p2;
import p.*;
class Test extends Foo {
{
Test.super.foo();
}
}

View File

@@ -15,10 +15,13 @@
*/
package com.intellij.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.JavaTestUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCase {
public class Interface8MethodsHighlightingTest extends LightCodeInsightFixtureTestCase {
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods";
public void testStaticMethod() { doTest(); }
@@ -39,6 +42,13 @@ public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCa
doTest(false, false);
}
public void testSuperProtectedCalls() throws Exception {
myFixture.addClass("package p; public class Foo {" +
" protected void foo(){}" +
"}");
doTest();
}
public void testIDEA120498() { doTest(false, false); }
private void doTest() {
@@ -46,6 +56,19 @@ public class Interface8MethodsHighlightingTest extends LightDaemonAnalyzerTestCa
}
private void doTest(boolean checkWarnings, boolean checkInfos) {
doTestNewInference(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos);
String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
myFixture.configureByFile(filePath);
myFixture.checkHighlighting(checkWarnings, checkInfos, false);
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
}
}