mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract functional: don't show error dialogs (IDEA-174180)
unable to perform in complex cases instead
This commit is contained in:
+17
-1
@@ -42,6 +42,7 @@ import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.refactoring.util.VariableData;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -67,8 +68,12 @@ public class IntroduceFunctionalVariableHandler extends IntroduceVariableHandler
|
||||
MyExtractMethodProcessor processor =
|
||||
new MyExtractMethodProcessor(project, editor, elementsInCopy, null, IntroduceFunctionalVariableAction.REFACTORING_NAME, null,
|
||||
HelpID.INTRODUCE_VARIABLE);
|
||||
processor.setShowErrorDialogs(false);
|
||||
try {
|
||||
processor.prepare();
|
||||
if (!processor.prepare()) {
|
||||
showErrorMessage(project, editor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (PrepareFailedException e) {
|
||||
showErrorMessage(project, editor);
|
||||
@@ -259,6 +264,17 @@ public class IntroduceFunctionalVariableHandler extends IntroduceVariableHandler
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(@Nullable Pass<ExtractMethodProcessor> pass) throws PrepareFailedException {
|
||||
final boolean prepare = super.prepare(pass);
|
||||
if (prepare) {
|
||||
if (myNotNullConditionalCheck || myNullConditionalCheck) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return prepare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDialog() {
|
||||
if (!myInputVariables.hasInstanceFields() && myInputVariables.getInputVariables().isEmpty() ||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
{
|
||||
int x = 0, y;
|
||||
<selection>y = ++x;</selection>
|
||||
System.out.println("x = " + x);
|
||||
System.out.println("y = " + y);
|
||||
}
|
||||
}
|
||||
+11
@@ -63,6 +63,17 @@ public class IntroduceFunctionalVariableTest extends LightRefactoringTestCase {
|
||||
doTest(0);
|
||||
}
|
||||
|
||||
public void testIgnoreMethodObjectSuggestion() throws Exception {
|
||||
try {
|
||||
doTest();
|
||||
fail("Unable to perform is expected");
|
||||
}
|
||||
catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
|
||||
assertEquals("Cannot perform refactoring.\n" +
|
||||
"Extract Functional Variable is not supported in current context", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoSuggestionForInaccessibleInterface() throws Exception {
|
||||
try {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user