mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce: postpone warning that selection is invalid
This commit is contained in:
+8
-1
@@ -452,7 +452,14 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase
|
||||
|
||||
@Override
|
||||
public void pass(final ElementToWorkOn elementToWorkOn) {
|
||||
if (elementToWorkOn == null) return;
|
||||
if (elementToWorkOn == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (elementToWorkOn.getExpression() == null && elementToWorkOn.getLocalVariable() == null) {
|
||||
ElementToWorkOn.showNothingSelectedErrorMessage(editor, getRefactoringName(), getHelpID(), project);
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean hasRunTemplate = LookupManager.getActiveLookup(editor) == null;
|
||||
if (elementToWorkOn.getExpression() == null) {
|
||||
|
||||
@@ -171,22 +171,23 @@ public class ElementToWorkOn {
|
||||
expr = IntroduceVariableBase.getSelectedExpression(project, file, startOffset, endOffset);
|
||||
}
|
||||
|
||||
if (localVar == null) {
|
||||
if (expr != null) {
|
||||
final String errorMessage = IntroduceVariableBase.getErrorMessage(expr);
|
||||
if (errorMessage != null) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, errorMessage, refactoringName, helpId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (expr == null) {
|
||||
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.local.or.expression.name"));
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, message, refactoringName, helpId);
|
||||
if (localVar == null && expr != null) {
|
||||
final String errorMessage = IntroduceVariableBase.getErrorMessage(expr);
|
||||
if (errorMessage != null) {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, errorMessage, refactoringName, helpId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new ElementToWorkOn(localVar, expr);
|
||||
}
|
||||
|
||||
public static void showNothingSelectedErrorMessage(final Editor editor,
|
||||
final String refactoringName,
|
||||
final String helpId,
|
||||
final Project project) {
|
||||
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.local.or.expression.name"));
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, message, refactoringName, helpId);
|
||||
}
|
||||
|
||||
public interface ElementsProcessor<T> {
|
||||
boolean accept(ElementToWorkOn el);
|
||||
|
||||
+9
-3
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.introduceParameter;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.FunctionalInterfaceSuggester;
|
||||
import com.intellij.codeInsight.completion.JavaCompletionUtil;
|
||||
@@ -83,7 +84,6 @@ import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
@@ -114,7 +114,13 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
@Override
|
||||
public void pass(final ElementToWorkOn elementToWorkOn) {
|
||||
if (elementToWorkOn == null) {
|
||||
introduceStrategy(project, editor, file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (elementToWorkOn.getLocalVariable() == null && elementToWorkOn.getExpression() == null) {
|
||||
if (!introduceStrategy(project, editor, file)) {
|
||||
ElementToWorkOn.showNothingSelectedErrorMessage(editor, REFACTORING_NAME, HelpID.INTRODUCE_PARAMETER, project);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -507,7 +513,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
return myInplaceIntroduceParameterPopup;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@VisibleForTesting
|
||||
public boolean introduceStrategy(final Project project, final Editor editor, PsiFile file) {
|
||||
final SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (selectionModel.hasSelection()) {
|
||||
|
||||
Reference in New Issue
Block a user