[java-refactoring] IDEA-350228 Missing method body after moving an instance method from interface to non-abstract class

GitOrigin-RevId: a54261f44b8e07273962d3c8c6c2a3db62d6fccf
This commit is contained in:
Tagir Valeev
2024-05-08 17:35:06 +00:00
committed by intellij-monorepo-bot
parent 11a73992ad
commit d34e599418
4 changed files with 33 additions and 0 deletions
@@ -2,6 +2,7 @@
package com.intellij.refactoring.move.moveInstanceMethod;
import com.intellij.codeInsight.ChangeContextUtil;
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.ide.util.EditorHelper;
import com.intellij.java.refactoring.JavaRefactoringBundle;
@@ -460,6 +461,11 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
final PsiCodeBlock body = myMethod.getBody();
if (body != null) {
replaceReferences(body);
} else {
if (myMethod.hasModifierProperty(PsiModifier.ABSTRACT) &&
!myTargetClass.isInterface() && !myTargetClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
CreateFromUsageUtils.setupMethodBody(myMethod);
}
}
final PsiMethod methodCopy = getPatternMethod();
@@ -0,0 +1,11 @@
public interface A {
public void n(A a);
public void <caret>m(B b);
}
class B {
}
@@ -0,0 +1,12 @@
public interface A {
public void n(A a);
}
class B {
public void m() {
}
}
@@ -104,6 +104,10 @@ public class MoveInstanceMethodTest extends LightRefactoringTestCase {
public void testUsageInAnonymousClass() {
doTest(true, 0);
}
public void testInterfaceMethodIntoClass() {
doTest(true, 0);
}
public void testConflictingLocalVariableAndTargetClassField() {
doTest(true, 0);