diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 914ff060280f..7d97295b8bab 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -1040,7 +1040,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (myRefCountHolder != null) { myRefCountHolder.registerReference(expression, result); } - if (result.getElement() != null && !result.isAccessible()) { + final PsiElement method = result.getElement(); + if (method != null && !result.isAccessible()) { final String accessProblem = HighlightUtil.buildProblemWithAccessDescription(expression, result); HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(accessProblem).create(); myHolder.add(info); @@ -1075,6 +1076,17 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) { myHolder.add(HighlightUtil.checkUnhandledExceptions(expression, expression.getTextRange())); } + if (!myHolder.hasErrorResults()) { + if (method instanceof PsiMethod && ((PsiMethod)method).hasModifierProperty(PsiModifier.ABSTRACT)) { + final PsiElement qualifier = expression.getQualifier(); + if (qualifier instanceof PsiSuperExpression) { + myHolder.add(HighlightInfo + .newHighlightInfo(HighlightInfoType.ERROR) + .range(expression.getReferenceNameElement()) + .descriptionAndTooltip("Abstract method '" + ((PsiMethod)method).getName() + "' cannot be accessed directly").create()); + } + } + } } @Override diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AbstractMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AbstractMethod.java new file mode 100644 index 000000000000..ace561a0e02c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AbstractMethod.java @@ -0,0 +1,20 @@ +class Test { + interface I { + int _(); + } + + static abstract class Parent { + abstract int foo() ; + } + + static abstract class Child extends Parent { + abstract int foo() ; + void test() { + I s = super::foo; + I s1 = this::foo; + + Parent sup = null; + I s2 = sup::foo; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java index c78f43b0c57f..c9db5801746a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/MethodRefHighlightingTest.java @@ -200,6 +200,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testAbstractMethod() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); }