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 88d41ed78a4d..e8c151990dc2 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 @@ -856,6 +856,7 @@ public class HighlightMethodUtil { boolean isExtension = method.hasModifierProperty(PsiModifier.DEFAULT); boolean isStatic = method.hasModifierProperty(PsiModifier.STATIC); + final List additionalFixes = new ArrayList(); String description = null; if (hasNoBody) { if (isExtension) { @@ -868,6 +869,10 @@ public class HighlightMethodUtil { else if (isInterface) { if (!isExtension && !isStatic) { description = JavaErrorMessages.message("interface.methods.cannot.have.body"); + if (PsiUtil.isLanguageLevel8OrHigher(method)) { + additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.DEFAULT, true, false)); + additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, true, false)); + } } else if (isExtension) { return HighlightUtil.checkExtensionMethodsFeature(method); @@ -886,12 +891,15 @@ public class HighlightMethodUtil { TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method); HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create(); - if (hasNoBody) { + if (!hasNoBody) { QuickFixAction.registerQuickFixAction(info, new DeleteMethodBodyFix(method)); } if (method.hasModifierProperty(PsiModifier.ABSTRACT) && isInterface) { QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, false, false)); } + for (IntentionAction intentionAction : additionalFixes) { + QuickFixAction.registerQuickFixAction(info, intentionAction); + } return info; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/afterMakeDefault.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/afterMakeDefault.java new file mode 100644 index 000000000000..0da0e5533366 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/afterMakeDefault.java @@ -0,0 +1,6 @@ +// "Make 'foo' default" "true" +interface I { + default void foo() { + System.out.println(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/afterMakeStatic.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/afterMakeStatic.java new file mode 100644 index 000000000000..a0b2b72d56eb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/afterMakeStatic.java @@ -0,0 +1,6 @@ +// "Make 'foo' static" "true" +interface I { + static void foo() { + System.out.println(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeDefault.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeDefault.java new file mode 100644 index 000000000000..6588917eb8bd --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeDefault.java @@ -0,0 +1,6 @@ +// "Make 'foo' default" "true" +interface I { + void foo() { + System.out.println(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeDefaultNoBody.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeDefaultNoBody.java new file mode 100644 index 000000000000..bc54ecf18921 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeDefaultNoBody.java @@ -0,0 +1,4 @@ +// "Make 'foo' default" "false" +interface I { + void foo(); +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeStatic.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeStatic.java new file mode 100644 index 000000000000..8e3937820655 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/modifier18/beforeMakeStatic.java @@ -0,0 +1,6 @@ +// "Make 'foo' static" "true" +interface I { + void foo() { + System.out.println(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Modifier18Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Modifier18Test.java new file mode 100644 index 000000000000..7e614b74738c --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/Modifier18Test.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon.quickFix; + +public class Modifier18Test extends LightQuickFixTestCase { + public void test() throws Exception { doAllTests(); } + + @Override + protected String getBasePath() { + return "/codeInsight/daemonCodeAnalyzer/quickFix/modifier18"; + } +}