IntroduceVariableAction and EncapsulateFieldAction both extends from BaseRunRefactoringAction

This commit is contained in:
Danila Ponomarenko
2012-06-08 17:55:27 +04:00
parent 5d980acadb
commit 4b3fdfb213
6 changed files with 64 additions and 64 deletions
@@ -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));
}
@@ -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<T extends RefactoringActionHandler> 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;
}
}
@@ -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<EncapsulateFieldsHandler> {
@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;
}
}
@@ -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<IntroduceVariableHandler> {
@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);
}
}
@@ -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<RefactoringActionHandler> {
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;
}
}
@@ -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