diff --git a/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java b/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java index 1aa15612fee9..fe508d2a6274 100644 --- a/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java +++ b/java/java-analysis-api/src/com/intellij/codeInsight/intention/QuickFixFactory.java @@ -321,4 +321,7 @@ public abstract class QuickFixFactory { @Nullable public abstract IntentionAction createCreateClassInPackageInModuleFix(@NotNull Module module, @Nullable String packageName); + + public abstract IntentionAction createPushDownMethodFix(); + } \ No newline at end of file diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index 8cd070f4bdda..1b4d3c7d013b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -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)); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java index 956857400c5c..2b4617aaecbe 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/intention/EmptyQuickFixFactory.java @@ -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; + } } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java index a9d31d7ed369..fe9c17be640e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java @@ -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; + } + }; + } } diff --git a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java index 837289c3e142..6ed0a8893b5a 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java @@ -256,7 +256,9 @@ public class JavaPushDownDelegate extends PushDownDelegate() { + System.out.println(); + } +} + +class Test implements I {} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pushDown/KeepBodyFromInterfaceMethod_after.java b/java/java-tests/testData/refactoring/pushDown/KeepBodyFromInterfaceMethod_after.java new file mode 100644 index 000000000000..47a1a3b85d96 --- /dev/null +++ b/java/java-tests/testData/refactoring/pushDown/KeepBodyFromInterfaceMethod_after.java @@ -0,0 +1,8 @@ +interface I { +} + +class Test implements I { + public void m() { + System.out.println(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java index 727c67e48cda..90d22b53124a 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java @@ -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();}