mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable from yet standalone switch expression (IDEA-206523)
This commit is contained in:
+10
-1
@@ -329,9 +329,18 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
if (statements.length == 1) {
|
||||
if (statements[0] instanceof PsiExpressionStatement) {
|
||||
tempExpr = ((PsiExpressionStatement) statements[0]).getExpression();
|
||||
} else if (statements[0] instanceof PsiReturnStatement) {
|
||||
}
|
||||
else if (statements[0] instanceof PsiReturnStatement) {
|
||||
tempExpr = ((PsiReturnStatement)statements[0]).getReturnValue();
|
||||
}
|
||||
else if (statements[0] instanceof PsiSwitchStatement) {
|
||||
PsiExpression expr = JavaPsiFacade.getElementFactory(project).createExpressionFromText(statements[0].getText(), statements[0]);
|
||||
TextRange range = statements[0].getTextRange();
|
||||
final RangeMarker rangeMarker = FileDocumentManager.getInstance().getDocument(file.getVirtualFile()).createRangeMarker(range);
|
||||
expr.putUserData(ElementToWorkOn.TEXT_RANGE, rangeMarker);
|
||||
expr.putUserData(ElementToWorkOn.PARENT, statements[0]);
|
||||
return expr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class MyTest {
|
||||
{
|
||||
String temp = switch (0) {
|
||||
default:
|
||||
break "";
|
||||
};
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyTest {
|
||||
{
|
||||
<selection>switch (0) {
|
||||
default: break "";
|
||||
}</selection>
|
||||
}
|
||||
}
|
||||
@@ -259,6 +259,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
public void testFromSwitchStatementJava12Preview() {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
public void testDeclareTernary() {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user