mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EnsureCodeBlockImpl: fix handling of incomplete while statements w/o body (EA-144041)
GitOrigin-RevId: 23e8a6f207cd4dc54b6f3582564b73fee8c9a568
This commit is contained in:
committed by
intellij-monorepo-bot
parent
13044f8b84
commit
6566e81a81
@@ -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());
|
||||
|
||||
+8
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user