mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-262335 refactor this: suggest convert to instance method only on method declaration
GitOrigin-RevId: f1b5643dae2ac2661039d13caea2bfcc6620392d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d77d06abb4
commit
ac9a14f565
+10
-1
@@ -16,6 +16,7 @@
|
||||
package com.intellij.refactoring.convertToInstanceMethod;
|
||||
|
||||
import com.intellij.java.refactoring.JavaRefactoringBundle;
|
||||
import com.intellij.lang.ContextAwareActionHandler;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -27,6 +28,8 @@ import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.actions.BaseRefactoringAction;
|
||||
import com.intellij.refactoring.actions.RefactoringActionContextUtil;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
@@ -39,7 +42,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class ConvertToInstanceMethodHandler implements RefactoringActionHandler {
|
||||
public class ConvertToInstanceMethodHandler implements RefactoringActionHandler, ContextAwareActionHandler {
|
||||
private static final Logger LOG = Logger.getInstance(ConvertToInstanceMethodHandler.class);
|
||||
|
||||
@Override
|
||||
@@ -122,6 +125,12 @@ public class ConvertToInstanceMethodHandler implements RefactoringActionHandler
|
||||
new ConvertToInstanceMethodDialog(method, ArrayUtil.toObjectArray(targetQualifiers)).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
|
||||
PsiElement caretElement = BaseRefactoringAction.getElementAtCaret(editor, file);
|
||||
return RefactoringActionContextUtil.getJavaMethodHeader(caretElement) != null;
|
||||
}
|
||||
|
||||
static @NlsContexts.DialogTitle String getRefactoringName() {
|
||||
return JavaRefactoringBundle.message("convert.to.instance.method.title");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
public class Test {
|
||||
|
||||
int x;
|
||||
|
||||
static void foo<caret>(int y){
|
||||
System.out.println(x + y);
|
||||
}
|
||||
|
||||
void test(){
|
||||
foo(y);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
public class Test {
|
||||
|
||||
int x;
|
||||
|
||||
static void foo(int y){
|
||||
System.out.println(x + y);
|
||||
}
|
||||
|
||||
void test(){
|
||||
foo<caret>(y);
|
||||
}
|
||||
}
|
||||
@@ -152,6 +152,14 @@ class RefactorThisTest: LightJavaCodeInsightTestCase() {
|
||||
assertFalse(doActionExists<MakeStaticAction>())
|
||||
}
|
||||
|
||||
fun testConvertToInstanceMethod() {
|
||||
assertTrue(doActionExists<ConvertToInstanceMethodAction>())
|
||||
}
|
||||
|
||||
fun testConvertToInstanceMethodFiltered() {
|
||||
assertFalse(doActionExists<ConvertToInstanceMethodAction>())
|
||||
}
|
||||
|
||||
private inline fun <reified A> doActionExists(): Boolean {
|
||||
configureByFile("$BASE_PATH/${getTestName(false)}.java")
|
||||
val actions = findAvailableActions()
|
||||
|
||||
Reference in New Issue
Block a user