IDEA-58132: 'Extract interface' action should not be available in plain XML file

This commit is contained in:
Dmitry Avdeev
2010-08-30 17:35:50 +04:00
parent 64fdd2d9af
commit 5e71677db7
13 changed files with 29 additions and 21 deletions
@@ -34,7 +34,7 @@ public class AnonymousToInnerAction extends BaseRefactoringAction {
return false;
}
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
final PsiElement targetElement = file.findElementAt(editor.getCaretModel().getOffset());
if (PsiTreeUtil.getParentOfType(targetElement, PsiAnonymousClass.class) != null) {
return true;
@@ -49,4 +49,4 @@ public class AnonymousToInnerAction extends BaseRefactoringAction {
public RefactoringActionHandler getHandler(DataContext dataContext) {
return new AnonymousToInnerHandler();
}
}
}
@@ -37,7 +37,7 @@ public class ChangeSignatureAction extends BaseRefactoringAction {
return elements.length == 1 && (elements[0] instanceof PsiMethod || elements[0] instanceof PsiClass);
}
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
PsiElement targetMember = findTargetMember(file, editor);
if (targetMember == null) return false;
final ChangeSignatureHandler targetHandler = getChangeSignatureHandler(targetMember.getLanguage());
@@ -33,7 +33,7 @@ public class ConvertToInstanceMethodAction extends BaseRefactoringAction {
return elements.length == 1 && elements[0] instanceof PsiMethod;
}
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, final Editor editor, PsiFile file, DataContext context) {
if (element instanceof PsiIdentifier) element = element.getParent();
return element instanceof PsiMethod && ((PsiMethod) element).hasModifierProperty(PsiModifier.STATIC);
}
@@ -33,7 +33,7 @@ public class InvertBooleanAction extends BaseRefactoringAction {
return elements.length == 1 && (elements[0] instanceof PsiMethod || elements[0] instanceof PsiVariable);
}
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
if (element instanceof PsiVariable) {
return PsiType.BOOLEAN.equals(((PsiVariable) element).getType());
}
@@ -39,7 +39,7 @@ public class MakeStaticAction extends BaseRefactoringAction {
return (elements.length == 1) && (elements[0] instanceof PsiMethod) && !((PsiMethod)elements[0]).isConstructor();
}
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, final Editor editor, PsiFile file, DataContext context) {
if (element instanceof PsiIdentifier) {
element = element.getParent();
}
@@ -37,7 +37,7 @@ public class TempWithQueryAction extends BaseRefactoringAction{
return new TempWithQueryHandler();
}
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
return element instanceof PsiLocalVariable && ((PsiLocalVariable) element).getInitializer() != null;
}
}
@@ -34,7 +34,7 @@ public class ChangeTypeSignatureAction extends BaseRefactoringAction {
return true;
}
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
final PsiElement psiElement = file.findElementAt(editor.getCaretModel().getOffset());
final PsiReferenceParameterList referenceParameterList = PsiTreeUtil.getParentOfType(psiElement, PsiReferenceParameterList.class);
if (referenceParameterList != null) {
@@ -46,4 +46,4 @@ public class ChangeTypeSignatureAction extends BaseRefactoringAction {
public RefactoringActionHandler getHandler(DataContext dataContext) {
return new ChangeTypeSignatureHandler();
}
}
}
@@ -20,10 +20,12 @@ import com.intellij.lang.LanguageRefactoringSupport;
import com.intellij.lang.refactoring.RefactoringSupportProvider;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.ExtensionPointListener;
import com.intellij.openapi.extensions.PluginDescriptor;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.refactoring.RefactoringActionHandler;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -77,6 +79,11 @@ public abstract class BasePlatformRefactoringAction extends BaseRefactoringActio
return null;
}
@Override
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
return getHandler(context) != null;
}
protected boolean isAvailableForLanguage(final Language language) {
List<RefactoringSupportProvider> providers = LanguageRefactoringSupport.INSTANCE.allForLanguage(language);
return ContainerUtil.find(providers, myCondition) != null;
@@ -48,7 +48,7 @@ public abstract class BaseRefactoringAction extends AnAction {
protected abstract boolean isEnabledOnElements(PsiElement[] elements);
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
return true;
}
@@ -133,7 +133,7 @@ public abstract class BaseRefactoringAction extends AnAction {
boolean isVisible = ContainerUtil.find(languages, myLanguageCondition) != null;
if (isVisible) {
boolean isEnabled = isAvailableOnElementInEditorAndFile(element, editor, file);
boolean isEnabled = isAvailableOnElementInEditorAndFile(element, editor, file, dataContext);
if (!isEnabled) {
disableAction(e);
}
@@ -211,4 +211,4 @@ public abstract class BaseRefactoringAction extends AnAction {
return filtered == null ? psiElements : filtered.toArray(new PsiElement[filtered.size()]);
}
}
}
@@ -25,6 +25,7 @@ import com.intellij.lang.Language;
import com.intellij.lang.refactoring.InlineActionHandler;
import com.intellij.lang.refactoring.InlineHandlers;
import com.intellij.lang.refactoring.RefactoringSupportProvider;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.psi.PsiElement;
@@ -46,7 +47,7 @@ public class InlineAction extends BasePlatformRefactoringAction {
}
@Override
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
return hasInlineActionHandler(element, PsiUtilBase.getLanguageInEditor(editor, element.getProject()), editor);
}
@@ -45,7 +45,7 @@ public class SafeDeleteAction extends BaseRefactoringAction {
return true;
}
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file) {
protected boolean isAvailableOnElementInEditorAndFile(final PsiElement element, final Editor editor, PsiFile file, DataContext context) {
return SafeDeleteProcessor.validElement(element);
}
@@ -53,4 +53,4 @@ public class SafeDeleteAction extends BaseRefactoringAction {
return new SafeDeleteHandler();
}
}
}
@@ -72,8 +72,8 @@ public class ExtractManagedDependenciesAction extends BaseRefactoringAction {
}
@Override
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file) {
if (!super.isAvailableOnElementInEditorAndFile(element, editor, file)) return false;
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
if (!super.isAvailableOnElementInEditorAndFile(element, editor, file, context)) return false;
return findDependencyAndParent(file, editor) != null;
}
@@ -254,4 +254,4 @@ public class ExtractManagedDependenciesAction extends BaseRefactoringAction {
myExtractExclusions = extractExclusions;
}
}
}
}
@@ -75,8 +75,8 @@ public class IntroducePropertyAction extends BaseRefactoringAction {
}
@Override
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file) {
if (!super.isAvailableOnElementInEditorAndFile(element, editor, file)) return false;
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
if (!super.isAvailableOnElementInEditorAndFile(element, editor, file, context)) return false;
return getSelectedElementAndTextRange(editor, file) != null;
}
@@ -359,4 +359,4 @@ public class IntroducePropertyAction extends BaseRefactoringAction {
}
return isInsideProperty;
}
}
}