mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java-completion] IDEA-331975 'Complete Current Statement' invoked on the 'while' keyword does not insert opening parenthesis
GitOrigin-RevId: 3d61667b9af08123dddef7f74e346473187266cd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
291026bc68
commit
ce7ea33a0a
@@ -54,8 +54,7 @@ public class MissingLoopBodyFixer implements Fixer {
|
||||
if (BasicJavaAstTreeUtil.is(body, BASIC_BLOCK_STATEMENT)) return;
|
||||
if (body != null && startLine(doc, body) == startLine(doc, loopStatement)) return;
|
||||
|
||||
ASTNode eltToInsertAfter = BasicJavaAstTreeUtil.getRParenth(loopStatement);
|
||||
fixLoopBody(editor, processor, loopStatement, doc, body, eltToInsertAfter);
|
||||
fixLoopBody(editor, processor, loopStatement, doc, body);
|
||||
}
|
||||
|
||||
private static ASTNode getLoopParent(@NotNull ASTNode element) {
|
||||
@@ -115,8 +114,8 @@ public class MissingLoopBodyFixer implements Fixer {
|
||||
@NotNull AbstractBasicJavaSmartEnterProcessor processor,
|
||||
@NotNull ASTNode loop,
|
||||
@NotNull Document doc,
|
||||
@Nullable ASTNode body,
|
||||
@Nullable ASTNode eltToInsertAfter) {
|
||||
@Nullable ASTNode body) {
|
||||
ASTNode eltToInsertAfter = BasicJavaAstTreeUtil.getRParenth(loop);
|
||||
PsiElement loopElement = BasicJavaAstTreeUtil.toPsi(loop);
|
||||
if (body != null && eltToInsertAfter != null) {
|
||||
PsiElement bodyElement = BasicJavaAstTreeUtil.toPsi(body);
|
||||
@@ -139,8 +138,13 @@ public class MissingLoopBodyFixer implements Fixer {
|
||||
}
|
||||
int offset = eltToInsertAfter.getTextRange().getEndOffset();
|
||||
if (needToClose) {
|
||||
doc.insertString(offset, ")");
|
||||
offset++;
|
||||
if (BasicJavaAstTreeUtil.getLParenth(loop) == null) {
|
||||
doc.insertString(offset, "()");
|
||||
offset += 2;
|
||||
} else {
|
||||
doc.insertString(offset, ")");
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
processor.insertBraces(editor, offset);
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
|
||||
@@ -205,6 +205,8 @@ public abstract class AbstractBasicCompleteStatementTest extends LightPlatformCo
|
||||
public void testParenthesized() { doTest(); }
|
||||
|
||||
public void testCompleteBreak() { doTest(); }
|
||||
|
||||
public void testNakedWhile() { doTest(); }
|
||||
|
||||
public void testCompleteIfNextLineBraceStyle() {
|
||||
myJavaSettings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class Foo {
|
||||
{
|
||||
while<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
class Foo {
|
||||
{
|
||||
while (<caret>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user