mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
push down: don't remove body when it's possible to keep it (IDEA-114041)
add intention with suggestion to push down
This commit is contained in:
@@ -321,4 +321,7 @@ public abstract class QuickFixFactory {
|
||||
|
||||
@Nullable
|
||||
public abstract IntentionAction createCreateClassInPackageInModuleFix(@NotNull Module module, @Nullable String packageName);
|
||||
|
||||
public abstract IntentionAction createPushDownMethodFix();
|
||||
|
||||
}
|
||||
+1
@@ -1306,6 +1306,7 @@ public class HighlightMethodUtil {
|
||||
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
if (!hasNoBody) {
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createDeleteMethodBodyFix(method));
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createPushDownMethodFix());
|
||||
}
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT) && !isInterface) {
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, false, false));
|
||||
|
||||
+5
@@ -717,4 +717,9 @@ public class EmptyQuickFixFactory extends QuickFixFactory {
|
||||
public IntentionAction createCreateClassInPackageInModuleFix(@NotNull Module module, @Nullable String packageName) {
|
||||
return QuickFixes.EMPTY_FIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentionAction createPushDownMethodFix() {
|
||||
return QuickFixes.EMPTY_FIX;
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -18,6 +18,7 @@ import com.intellij.codeInsight.intention.IntentionManager;
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory;
|
||||
import com.intellij.codeInsight.intention.impl.CreateClassInPackageInModuleFix;
|
||||
import com.intellij.codeInsight.intention.impl.ReplaceAssignmentWithComparisonFix;
|
||||
import com.intellij.codeInsight.intention.impl.RunRefactoringAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase;
|
||||
import com.intellij.codeInspection.ex.EntryPointsManagerBase;
|
||||
@@ -45,6 +46,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.ClassKind;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PropertyMemberType;
|
||||
import com.intellij.refactoring.memberPushDown.JavaPushDownHandler;
|
||||
import com.intellij.util.DocumentUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -918,4 +920,15 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
public IntentionAction createCreateClassInPackageInModuleFix(@NotNull Module module, @Nullable String packageName) {
|
||||
return CreateClassInPackageInModuleFix.createFix(module, packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentionAction createPushDownMethodFix() {
|
||||
return new RunRefactoringAction(new JavaPushDownHandler(), "Push method down...") {
|
||||
@NotNull
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.NORMAL;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -256,7 +256,9 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
if (sourceClass.isInterface() && !targetClass.isInterface()) {
|
||||
PsiUtil.setModifierProperty(newMember, PsiModifier.PUBLIC, true);
|
||||
if (oldMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
RefactoringUtil.makeMethodAbstract(targetClass, (PsiMethod)newMember);
|
||||
if (oldMethod.getBody() == null) {
|
||||
RefactoringUtil.makeMethodAbstract(targetClass, (PsiMethod)newMember);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiUtil.setModifierProperty(newMember, PsiModifier.DEFAULT, false);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
interface I {
|
||||
void m<caret>() {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
class Test implements I {}
|
||||
@@ -0,0 +1,8 @@
|
||||
interface I {
|
||||
}
|
||||
|
||||
class Test implements I {
|
||||
public void m() {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
public void testThisSuperExpressions() {doTest();}
|
||||
public void testMethodsInheritedFromSuper() {doTest();}
|
||||
public void testCopyAnnotationsFromSuper() {doTest();}
|
||||
public void testKeepBodyFromInterfaceMethod() {doTest();}
|
||||
|
||||
public void testInterfaceMethodToClass() { doTest();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user