mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
hide wrap method return value and remove middleman refactorings when inappropriate
This commit is contained in:
@@ -17,9 +17,12 @@ package com.intellij.refactoring.actions;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsHandler;
|
||||
|
||||
@@ -28,6 +31,19 @@ public class EncapsulateFieldsAction extends BaseRefactoringAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
|
||||
final PsiElement psiElement = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
final PsiClass containingClass = PsiTreeUtil.getParentOfType(psiElement, PsiClass.class, false);
|
||||
if (containingClass != null) {
|
||||
final PsiField[] fields = containingClass.getFields();
|
||||
for (PsiField field : fields) {
|
||||
if (isAcceptedField(field)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEnabledOnElements(PsiElement[] elements) {
|
||||
if (elements.length == 1) {
|
||||
return elements[0] instanceof PsiClass && elements[0].getLanguage().isKindOf(JavaLanguage.INSTANCE) || isAcceptedField(elements[0]);
|
||||
|
||||
@@ -16,21 +16,27 @@
|
||||
package com.intellij.refactoring.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.removemiddleman.RemoveMiddlemanHandler;
|
||||
|
||||
public class RemoveMiddlemanAction extends BaseRefactoringAction{
|
||||
|
||||
|
||||
protected RefactoringActionHandler getHandler(DataContext context) {
|
||||
return new RemoveMiddlemanHandler();
|
||||
}
|
||||
return new RemoveMiddlemanHandler();
|
||||
}
|
||||
|
||||
public boolean isAvailableInEditorOnly(){
|
||||
return false;
|
||||
@Override
|
||||
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
|
||||
return element instanceof PsiField;
|
||||
}
|
||||
|
||||
public boolean isAvailableInEditorOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEnabledOnElements(PsiElement[] elements) {
|
||||
|
||||
+16
-6
@@ -16,8 +16,8 @@
|
||||
package com.intellij.refactoring.wrapreturnvalue;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.actions.BaseRefactoringAction;
|
||||
@@ -32,11 +32,21 @@ public class WrapReturnValueAction extends BaseRefactoringAction{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailableOnElementInEditorAndFile(PsiElement element, Editor editor, PsiFile file, DataContext context) {
|
||||
final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
|
||||
if (psiMethod != null && !(psiMethod instanceof PsiCompiledElement)) {
|
||||
final PsiType returnType = psiMethod.getReturnType();
|
||||
return returnType != null && returnType != PsiType.VOID;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEnabledOnElements(PsiElement[] elements) {
|
||||
if (elements.length != 1) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement element = elements[0];
|
||||
if (elements.length != 1) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement element = elements[0];
|
||||
final PsiMethod containingMethod =
|
||||
PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
|
||||
return containingMethod != null;
|
||||
|
||||
@@ -520,7 +520,7 @@ action.SafeDelete.description=Delete the selected class, method or field, checki
|
||||
action.ExtractMethod.text=_Method...
|
||||
action.ExtractMethod.description=Turn the selected code fragment into a method
|
||||
action.RemoveMiddleman.text=Remove _Middleman...
|
||||
action.RemoveMiddleman.description=Get the client to call the delegate directly
|
||||
action.RemoveMiddleman.description=Inline delegate to the selected field methods
|
||||
action.MethodDuplicates.text=Find and Replace _Code Duplicates...
|
||||
action.MethodDuplicates.description=Finds code in selected scope that can be transformed into a call of selected method/constant
|
||||
action.InvertBoolean.text=Invert _Boolean...
|
||||
@@ -1193,7 +1193,7 @@ group.ViewRecentActions.text=View Recent Actions Group
|
||||
group.NewGroup1.text=New Group (1)
|
||||
group.NewGroup2.text=New Group (2)
|
||||
action.NewModuleInGroup.text=Module
|
||||
action.WrapReturnValue.text=Wrap Re_turn Value...
|
||||
action.WrapReturnValue.text=Wrap Method Re_turn Value...
|
||||
action.WrapReturnValue.description=Wrap return value of the specified method with object
|
||||
action.ReplaceConstructorWithBuilder.text=Replace Constructor with Builder...
|
||||
action.ReplaceConstructorWithBuilder.description=Replace Constructor with Builder
|
||||
|
||||
Reference in New Issue
Block a user