[java] add method body: add default modifier if method in interface must have body (IDEA-279878)

GitOrigin-RevId: f856b41110e09d4e6d10b4841ba455cb7b8b69c7
This commit is contained in:
Anna Kozlova
2021-10-15 08:41:09 +00:00
committed by intellij-monorepo-bot
parent f6fb4ecf53
commit df4439ba6c
3 changed files with 31 additions and 1 deletions
@@ -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);
}
@@ -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();
}
}
@@ -0,0 +1,10 @@
// "Make 'a.f' not abstract" "true"
interface a {
String f();
}
class b implements a {
void z() {
a.super.<caret>f();
}
}