got rid of BaseRefactoringAction

This commit is contained in:
Danila Ponomarenko
2012-06-24 18:24:05 +04:00
parent 79b79ccd83
commit 4f30409292
8 changed files with 26 additions and 96 deletions
@@ -1,49 +0,0 @@
/*
* 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.intention.PsiElementBaseIntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.SyntheticElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author Danila Ponomarenko
*/
public abstract class BaseRefactoringAction extends PsiElementBaseIntentionAction implements RefactoringAction{
@Override
public final boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
return !(element instanceof SyntheticElement) && isAvailableOverride(project, editor, element);
}
protected abstract boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element);
@Override
public final boolean startInWriteAction() {
return false;
}
@Override
public final Icon getIcon(int flags) {
return REFACTORING_BULB;
}
}
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.refactoring.BaseRefactoringIntentionAction;
import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsHandler;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -27,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
/**
* @author Danila Ponomarenko
*/
public class EncapsulateFieldAction extends BaseRefactoringAction {
public class EncapsulateFieldAction extends BaseRefactoringIntentionAction {
@NotNull
@Override
@@ -42,7 +43,11 @@ public class EncapsulateFieldAction extends BaseRefactoringAction {
}
@Override
protected boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (element instanceof SyntheticElement){
return false;
}
final PsiField field = getField(element);
return field != null && !field.hasModifierProperty(PsiModifier.FINAL) && !field.hasModifierProperty(PsiModifier.PRIVATE);
}
@@ -20,15 +20,15 @@ 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.BaseRefactoringIntentionAction;
import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Danila Ponomarenko
*/
public class IntroduceVariableIntentionAction extends BaseRefactoringAction {
public class IntroduceVariableIntentionAction extends BaseRefactoringIntentionAction {
@NotNull
@Override
public String getText() {
@@ -42,7 +42,11 @@ public class IntroduceVariableIntentionAction extends BaseRefactoringAction {
}
@Override
protected boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (element instanceof SyntheticElement){
return false;
}
final PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element,PsiExpressionStatement.class);
if (statement == null){
return false;
@@ -1,30 +0,0 @@
/*
* 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.intention.IntentionAction;
import com.intellij.codeInsight.intention.LowPriorityAction;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.Iconable;
import javax.swing.*;
/**
* @author Danila Ponomarenko
*/
public interface RefactoringAction extends IntentionAction, Iconable, LowPriorityAction {
public static final Icon REFACTORING_BULB = AllIcons.Actions.RefactoringBulb;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* 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.
@@ -17,7 +17,8 @@ package com.intellij.codeInsight.intention.impl;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.BaseRefactoringIntentionAction;
import com.intellij.refactoring.RefactoringActionHandler;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -28,7 +29,7 @@ import javax.swing.*;
* User: anna
* Date: 9/5/11
*/
public class RunRefactoringAction implements RefactoringAction {
public class RunRefactoringAction extends BaseRefactoringIntentionAction {
private final RefactoringActionHandler myHandler;
private final String myCommandName;
@@ -50,13 +51,13 @@ public class RunRefactoringAction implements RefactoringAction {
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
return true;
}
@Override
public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
myHandler.invoke(project, editor, file, null);
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
myHandler.invoke(project, editor, element.getContainingFile(), null);
}
@Override