diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index 8c1c539d010b..05fedc0990e5 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -850,16 +850,21 @@ public class HighlightMethodUtil { static HighlightInfo checkMethodCanHaveBody(PsiMethod method) { if (method.getBody() == null) return null; PsiClass aClass = method.getContainingClass(); + boolean isInterface = aClass != null && aClass.isInterface(); + boolean isExtension = PsiUtil.isExtensionMethod(method); String message = null; - if (aClass != null && aClass.isInterface()) { - if (!PsiUtil.isExtensionMethod(method)) { + if (isInterface) { + if (!isExtension) { message = JavaErrorMessages.message("interface.methods.cannot.have.body"); } else { return HighlightUtil.checkExtensionMethodsFeature(method); } } + else if (isExtension) { + message = JavaErrorMessages.message("extension.method.in.class"); + } else if (method.hasModifierProperty(PsiModifier.ABSTRACT)) { message = JavaErrorMessages.message("abstract.methods.cannot.have.a.body"); } @@ -871,7 +876,7 @@ public class HighlightMethodUtil { TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method); HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, message); QuickFixAction.registerQuickFixAction(info, new DeleteMethodBodyFix(method)); - if (method.hasModifierProperty(PsiModifier.ABSTRACT) && aClass != null && !aClass.isInterface()) { + if (method.hasModifierProperty(PsiModifier.ABSTRACT) && isInterface) { IntentionAction fix = QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, false, false); QuickFixAction.registerQuickFixAction(info, fix); } diff --git a/java/java-psi-impl/src/messages/JavaErrorMessages.properties b/java/java-psi-impl/src/messages/JavaErrorMessages.properties index 597334998586..09b98290be71 100644 --- a/java/java-psi-impl/src/messages/JavaErrorMessages.properties +++ b/java/java-psi-impl/src/messages/JavaErrorMessages.properties @@ -173,6 +173,7 @@ incompatible.types.html.tooltip=\ interface.methods.cannot.have.body=Interface methods cannot have body abstract.methods.cannot.have.a.body=Abstract methods cannot have a body native.methods.cannot.have.a.body=Native methods cannot have a body +extension.method.in.class=Extension methods can only be used within an interface instance.method.cannot.override.static.method=Instance method ''{0}'' in ''{1}'' cannot override static method ''{2}'' in ''{3}'' static.method.cannot.override.instance.method=Static method ''{0}'' in ''{1}'' cannot override instance method ''{2}'' in ''{3}'' diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ExtensionMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ExtensionMethods.java index 2bb985bef33e..144d50c248f7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ExtensionMethods.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ExtensionMethods.java @@ -43,4 +43,8 @@ class C { } }.m(); } +} + +class D { + void m() default { } } \ No newline at end of file