mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
allow inplace refactoring to decide if restart makes sense when no elements are found under caret (IDEA-167501)
This commit is contained in:
+20
@@ -15,12 +15,14 @@
|
||||
*/
|
||||
package com.intellij.refactoring.introduceField;
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.TransactionGuard;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -238,6 +240,24 @@ public class InplaceIntroduceConstantPopup extends AbstractInplaceIntroduceField
|
||||
return handler instanceof IntroduceConstantHandler && super.startsOnTheSameElement(handler, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean startsOnTheSameElements(Editor editor,
|
||||
RefactoringActionHandler handler,
|
||||
PsiElement[] elements) {
|
||||
if (elements.length == 0 && handler instanceof IntroduceConstantHandler) {
|
||||
PsiVariable variable = getVariable();
|
||||
if (variable != null) {
|
||||
PsiReference reference = TargetElementUtil.findReference(editor);
|
||||
if (reference instanceof PsiReferenceExpression &&
|
||||
reference.resolve() == null &&
|
||||
Comparing.strEqual(variable.getName(), ((PsiReferenceExpression)reference).getReferenceName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return elements.length == 1 && startsOnTheSameElement(handler, elements[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performIntroduce() {
|
||||
final BaseExpressionToFieldHandler.Settings settings =
|
||||
|
||||
+6
-1
@@ -798,13 +798,18 @@ public abstract class InplaceRefactoring {
|
||||
public static boolean canStartAnotherRefactoring(Editor editor, Project project, RefactoringActionHandler handler, PsiElement... element) {
|
||||
final InplaceRefactoring inplaceRefactoring = getActiveInplaceRenamer(editor);
|
||||
return StartMarkAction.canStart(project) == null ||
|
||||
(inplaceRefactoring != null && element.length == 1 && inplaceRefactoring.startsOnTheSameElement(handler, element[0]));
|
||||
(inplaceRefactoring != null && inplaceRefactoring.startsOnTheSameElements(editor, handler, element));
|
||||
}
|
||||
|
||||
public static InplaceRefactoring getActiveInplaceRenamer(Editor editor) {
|
||||
return editor != null ? editor.getUserData(INPLACE_RENAMER) : null;
|
||||
}
|
||||
|
||||
protected boolean startsOnTheSameElements(Editor editor, RefactoringActionHandler handler,
|
||||
PsiElement[] element) {
|
||||
return element.length == 1 && startsOnTheSameElement(handler, element[0]);
|
||||
}
|
||||
|
||||
protected boolean startsOnTheSameElement(RefactoringActionHandler handler, PsiElement element) {
|
||||
return getVariable() == element;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user