mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
EA-76495 (IOE: PsiJavaParserFacadeImpl.createStatementFromText)
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.psi.controlFlow.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -80,7 +81,7 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
if (switchExpression == null) {
|
||||
return;
|
||||
}
|
||||
final PsiType switchExpressionType = switchExpression.getType();
|
||||
final PsiType switchExpressionType = RefactoringUtil.getTypeByExpressionWithExpectedType(switchExpression);
|
||||
if (switchExpressionType == null) {
|
||||
return;
|
||||
}
|
||||
@@ -110,10 +111,7 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
"i", switchExpression, true);
|
||||
}
|
||||
expressionText = variableName;
|
||||
declarationString =
|
||||
switchExpressionType.getPresentableText() + ' ' +
|
||||
variableName + " = " +
|
||||
switchExpression.getText() + ';';
|
||||
declarationString = switchExpressionType.getCanonicalText() + ' ' + variableName + " = " + switchExpression.getText() + ';';
|
||||
}
|
||||
else {
|
||||
hadSideEffects = false;
|
||||
@@ -334,7 +332,7 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
for (PsiLocalVariable variable : variables) {
|
||||
if (ReferencesSearch.search(variable, new LocalSearchScope(bodyStatements.toArray(new PsiElement[bodyStatements.size()]))).findFirst() != null) {
|
||||
final PsiType varType = variable.getType();
|
||||
ifStatementString.append(varType.getPresentableText());
|
||||
ifStatementString.append(varType.getCanonicalText());
|
||||
ifStatementString.append(' ');
|
||||
ifStatementString.append(variable.getName());
|
||||
ifStatementString.append(';');
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class Test {
|
||||
void foo(Object e) {
|
||||
Class<?> i = e.getClass();
|
||||
if (i.equals(RuntimeException.class)) {
|
||||
} else if (i.equals(IOException.class)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class Test {
|
||||
void foo(Object e) {
|
||||
<caret>switch(e.getClass()) {
|
||||
case RuntimeException.class:
|
||||
break;
|
||||
case IOException.class:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user