diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java index 883c17f21592..399b5d624ef0 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/PullAsAbstractUpFix.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInsight.intention.impl.RunRefactoringAction; import com.intellij.codeInsight.navigation.NavigationUtil; import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; import com.intellij.ide.util.PsiClassListCellRenderer; @@ -163,13 +164,13 @@ public class PullAsAbstractUpFix extends LocalQuickFixAndIntentionActionOnPsiEle name+= " and make it abstract"; } } - QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringIntention(new ExtractInterfaceHandler(), "Extract interface")); - QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringIntention(new ExtractSuperclassHandler(), "Extract superclass")); + QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringAction(new ExtractInterfaceHandler(), "Extract interface")); + QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringAction(new ExtractSuperclassHandler(), "Extract superclass")); } if (canBePulledUp) { - QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringIntention(new JavaPullUpHandler(), "Pull members up")); + QuickFixAction.registerQuickFixAction(highlightInfo, new RunRefactoringAction(new JavaPullUpHandler(), "Pull members up")); } QuickFixAction.registerQuickFixAction(highlightInfo, new PullAsAbstractUpFix(methodWithOverrides, name)); } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRunRefactoringAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRunRefactoringAction.java new file mode 100644 index 000000000000..b9fbab23fa76 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BaseRunRefactoringAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.codeInsight.intention.LowPriorityAction; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.util.Iconable; +import com.intellij.refactoring.RefactoringActionHandler; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author Danila Ponomarenko + */ +public abstract class BaseRunRefactoringAction implements IntentionAction, Iconable, LowPriorityAction { + public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb; + + @NotNull + @Override + public final String getFamilyName() { + return CodeInsightBundle.message("intention.refactoring.family"); + } + + @Override + public final boolean startInWriteAction() { + return false; + } + + @Override + public final Icon getIcon(int flags) { + return REFACTORING_BULB; + } +} \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java index 8e2588455db1..685f37b375b0 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/EncapsulateFieldAction.java @@ -16,13 +16,11 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.CodeInsightBundle; -import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; -import com.intellij.refactoring.JavaRefactoringActionHandlerFactory; -import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,7 +28,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Danila Ponomarenko */ -public class EncapsulateFieldAction implements IntentionAction { +public class EncapsulateFieldAction extends BaseRunRefactoringAction { @NotNull @Override @@ -38,12 +36,6 @@ public class EncapsulateFieldAction implements IntentionAction { return CodeInsightBundle.message("intention.encapsulate.field.text"); } - @NotNull - @Override - public String getFamilyName() { - return getText(); - } - @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final PsiField field = getField(getElement(editor, file)); @@ -58,8 +50,7 @@ public class EncapsulateFieldAction implements IntentionAction { return; } - final RefactoringActionHandler refactoringActionHandler = JavaRefactoringActionHandlerFactory.getInstance().createEncapsulateFieldsHandler(); - refactoringActionHandler.invoke(project, new PsiElement[]{field}, null); + new EncapsulateFieldsHandler().invoke(project, new PsiElement[]{field}, null); } @Nullable @@ -92,9 +83,4 @@ public class EncapsulateFieldAction implements IntentionAction { final int position = caretModel.getOffset(); return file.findElementAt(position); } - - @Override - public boolean startInWriteAction() { - return false; - } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java index 6b7277685a60..4ac04eaed610 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/IntroduceVariableAction.java @@ -16,14 +16,12 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.CodeInsightBundle; -import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.refactoring.JavaRefactoringActionHandlerFactory; -import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,7 +29,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Danila Ponomarenko */ -public class IntroduceVariableAction implements IntentionAction { +public class IntroduceVariableAction extends BaseRunRefactoringAction { @NotNull @Override @@ -39,12 +37,6 @@ public class IntroduceVariableAction implements IntentionAction { return CodeInsightBundle.message("intention.introduce.variable.text"); } - @NotNull - @Override - public String getFamilyName() { - return getText(); - } - @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final PsiElement element = getElement(editor, file); @@ -73,12 +65,6 @@ public class IntroduceVariableAction implements IntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final RefactoringActionHandler refactoringActionHandler = JavaRefactoringActionHandlerFactory.getInstance().createIntroduceVariableHandler(); - refactoringActionHandler.invoke(project, editor, file, null); - } - - @Override - public boolean startInWriteAction() { - return false; + new IntroduceVariableHandler().invoke(project, editor, file, null); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RunRefactoringIntention.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java similarity index 59% rename from java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RunRefactoringIntention.java rename to java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java index f053a18527b7..6462dbe404b9 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RunRefactoringIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/RunRefactoringAction.java @@ -13,31 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.codeInsight.daemon.impl.quickfix; +package com.intellij.codeInsight.intention.impl; -import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInsight.intention.LowPriorityAction; -import com.intellij.icons.AllIcons; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Iconable; import com.intellij.psi.PsiFile; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** * User: anna * Date: 9/5/11 */ -public class RunRefactoringIntention implements IntentionAction, Iconable, LowPriorityAction { - public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb; +public class RunRefactoringAction extends BaseRunRefactoringAction { private final RefactoringActionHandler myHandler; private final String myCommandName; - public RunRefactoringIntention(RefactoringActionHandler handler, String commandName) { + public RunRefactoringAction(RefactoringActionHandler handler, String commandName) { myHandler = handler; myCommandName = commandName; } @@ -48,29 +41,13 @@ public class RunRefactoringIntention implements IntentionAction, Iconable, LowPr return myCommandName; } - @NotNull - @Override - public String getFamilyName() { - return "Refactorings"; - } - @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return true; } @Override - public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { + public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { myHandler.invoke(project, editor, file, null); } - - @Override - public boolean startInWriteAction() { - return false; - } - - @Override - public Icon getIcon(int flags) { - return REFACTORING_BULB; - } } diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index 3139e449dd77..17413a924376 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -156,6 +156,7 @@ intention.make.type.generic.family=Make Type Generic intention.make.type.generic.text=Change type of {0} to {1} intention.split.if.family=Split If intention.split.if.text=Split into 2 if's +intention.refactoring.family=Refactoring intention.introduce.variable.text=Introduce local variable intention.encapsulate.field.text=Encapsulate field intention.implement.abstract.method.family=Implement Abstract Method