extract functional: don't show error dialogs (IDEA-174180)

unable to perform in complex cases instead
This commit is contained in:
Anna Kozlova
2017-06-08 17:49:08 +03:00
parent 703283b008
commit cb2eaa99e1
3 changed files with 36 additions and 1 deletions
@@ -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() ||
@@ -0,0 +1,8 @@
class Test {
{
int x = 0, y;
<selection>y = ++x;</selection>
System.out.println("x = " + x);
System.out.println("y = " + y);
}
}
@@ -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();