diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java index 7d8f8876772d..c75dc52f27be 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.daemon.QuickFixBundle; @@ -16,6 +16,8 @@ import com.intellij.psi.util.PsiUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + public final class AddMethodBodyFix implements IntentionActionWithFixAllOption { private final PsiMethod myMethod; private final @Nls String myText; @@ -59,6 +61,12 @@ public final class AddMethodBodyFix implements IntentionActionWithFixAllOption { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { PsiUtil.setModifierProperty(myMethod, PsiModifier.ABSTRACT, false); + if (Objects.requireNonNull(myMethod.getContainingClass()).isInterface() && + !myMethod.hasModifierProperty(PsiModifier.STATIC) && + !myMethod.hasModifierProperty(PsiModifier.DEFAULT) && + !myMethod.hasModifierProperty(PsiModifier.PRIVATE)) { + PsiUtil.setModifierProperty(myMethod, PsiModifier.DEFAULT, true); + } CreateFromUsageUtils.setupMethodBody(myMethod); CreateFromUsageUtils.setupEditor(myMethod, editor); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addMethodBody/afterSuperAndInterface.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addMethodBody/afterSuperAndInterface.java new file mode 100644 index 000000000000..0b1a81d69302 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addMethodBody/afterSuperAndInterface.java @@ -0,0 +1,12 @@ +// "Make 'a.f' not abstract" "true" +interface a { + default String f() { + return null; + } +} +class b implements a { + void z() { + a.super.f(); + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addMethodBody/beforeSuperAndInterface.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addMethodBody/beforeSuperAndInterface.java new file mode 100644 index 000000000000..1f4edb03bd94 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addMethodBody/beforeSuperAndInterface.java @@ -0,0 +1,10 @@ +// "Make 'a.f' not abstract" "true" +interface a { + String f(); +} +class b implements a { + void z() { + a.super.f(); + } +} +