mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
IDEA-259050 refactor this: don't search target element to Move between all possible parents
GitOrigin-RevId: c558f8718dcc473878acff1e29a09b96d9824d6c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b6ec937b27
commit
6b0c0c462d
@@ -0,0 +1,6 @@
|
||||
public class Test {
|
||||
|
||||
void test(){
|
||||
System.out.println<caret>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Test {
|
||||
|
||||
void test(){
|
||||
<caret>System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Test<caret> {
|
||||
|
||||
void test(){
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Test {
|
||||
|
||||
void test<caret>(){
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,22 @@ class RefactorThisTest: LightJavaCodeInsightTestCase() {
|
||||
assertFalse(doActionExists<SafeDeleteAction>())
|
||||
}
|
||||
|
||||
fun testMoveIsFilteredOnStatement() {
|
||||
assertFalse(doActionExists<MoveAction>())
|
||||
}
|
||||
|
||||
fun testMoveIsFilteredOnMethodReference() {
|
||||
assertFalse(doActionExists<MoveAction>())
|
||||
}
|
||||
|
||||
fun testMoveIsFilteredOnConstructor() {
|
||||
assertFalse(doActionExists<MoveAction>())
|
||||
}
|
||||
|
||||
fun testMoveOnMethodDeclaration() {
|
||||
assertTrue(doActionExists<MoveAction>())
|
||||
}
|
||||
|
||||
private inline fun <reified A> doActionExists(): Boolean {
|
||||
configureByFile("$BASE_PATH/${getTestName(false)}.java")
|
||||
return findAvailableActions().any { action -> action is A }
|
||||
|
||||
@@ -17,8 +17,12 @@
|
||||
package com.intellij.refactoring.actions;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.move.MoveHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -46,6 +50,23 @@ public class MoveAction extends BaseRefactoringAction {
|
||||
return MoveHandler.canMove(elements, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailableOnElementInEditorAndFile(@NotNull PsiElement element,
|
||||
@NotNull Editor editor,
|
||||
@NotNull PsiFile file,
|
||||
@NotNull DataContext context,
|
||||
@NotNull String place) {
|
||||
if (place.equals(ActionPlaces.REFACTORING_QUICKLIST)) {
|
||||
PsiElement caretElement = BaseRefactoringAction.getElementAtCaret(editor, file);
|
||||
if (PsiTreeUtil.isAncestor(element, caretElement, false)) {
|
||||
return isEnabledOnElements(new PsiElement[]{element});
|
||||
} else {
|
||||
return isEnabledOnElements(new PsiElement[]{caretElement});
|
||||
}
|
||||
}
|
||||
return super.isAvailableOnElementInEditorAndFile(element, editor, file, context, place);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledOnDataContext(@NotNull DataContext dataContext) {
|
||||
return MoveHandler.canMove(dataContext);
|
||||
|
||||
Reference in New Issue
Block a user