EnsureCodeBlockImpl: fix handling of incomplete while statements w/o body (EA-144041)

GitOrigin-RevId: 23e8a6f207cd4dc54b6f3582564b73fee8c9a568
This commit is contained in:
Tagir Valeev
2019-06-16 06:56:28 +03:00
committed by intellij-monorepo-bot
parent 13044f8b84
commit 6566e81a81
4 changed files with 18 additions and 0 deletions
@@ -169,6 +169,7 @@ class EnsureCodeBlockImpl {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
if (body == null) {
PsiWhileStatement newWhileStatement = (PsiWhileStatement)factory.createStatementFromText("while(true) {}", whileStatement);
Objects.requireNonNull(newWhileStatement.getCondition()).replace(oldCondition);
whileStatement = (PsiWhileStatement)whileStatement.replace(newWhileStatement);
blockBody = (PsiBlockStatement)Objects.requireNonNull(whileStatement.getBody());
oldCondition = Objects.requireNonNull(whileStatement.getCondition());
@@ -0,0 +1,8 @@
class Test {
void test(boolean foo) {
while (true) {
boolean temp = foo;
if (!temp) break;
}
}
}
@@ -0,0 +1,5 @@
class Test {
void test(boolean foo) {
while(<selection>foo</selection>)
}
}
@@ -210,6 +210,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "Node"));
}
public void testWhileConditionIncomplete() {
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "boolean"));
}
public void testField() {
doTest(new MockIntroduceVariableHandler("temp", false, false, false, CommonClassNames.JAVA_LANG_STRING));
}