mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
[java-rd] IDEA-322563 Improve editing experience in Remote Dev for Java
- fix while completion GitOrigin-RevId: 40827f77037557eab988d33d8170bd4446b8478a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
de67570ff3
commit
76d10b31f3
@@ -553,7 +553,7 @@ public final class BasicJavaAstTreeUtil {
|
||||
|
||||
@Nullable
|
||||
public static ASTNode getWhileCondition(@Nullable ASTNode element) {
|
||||
if (!is(element, BASIC_DO_WHILE_STATEMENT) ||
|
||||
if (!is(element, BASIC_DO_WHILE_STATEMENT) &&
|
||||
!is(element, BASIC_WHILE_STATEMENT)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -412,6 +412,8 @@ public abstract class AbstractBasicCompleteStatementTest extends LightPlatformCo
|
||||
public void testYieldSemicolon() { doTest(); }
|
||||
public void testCommentSmartEnter() { doTest(false); }
|
||||
|
||||
public void testWhileStatementWithCondition() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return new BasicDefaultLightProjectDescriptor();
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiThrowStatement;
|
||||
import com.intellij.psi.impl.source.BasicJavaAstTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MissingThrowExpressionFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, AbstractBasicJavaSmartEnterProcessor processor, @NotNull ASTNode astNode)
|
||||
throws IncorrectOperationException {
|
||||
PsiElement psiElement = BasicJavaAstTreeUtil.toPsi(astNode);
|
||||
if (psiElement instanceof PsiThrowStatement throwStatement) {
|
||||
if (throwStatement.getException() != null &&
|
||||
startLine(editor, throwStatement) == startLine(editor, throwStatement.getException())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int startOffset = throwStatement.getTextRange().getStartOffset();
|
||||
if (throwStatement.getException() != null) {
|
||||
editor.getDocument().insertString(startOffset + "throw".length(), ";");
|
||||
}
|
||||
processor.registerUnresolvedError(startOffset + "throw".length());
|
||||
}
|
||||
}
|
||||
|
||||
private static int startLine(Editor editor, PsiElement psiElement) {
|
||||
return editor.getDocument().getLineNumber(psiElement.getTextRange().getStartOffset());
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.BasicJavaAstTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WhileConditionFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, AbstractBasicJavaSmartEnterProcessor processor, @NotNull ASTNode astNode) throws IncorrectOperationException {
|
||||
PsiElement psiElement = BasicJavaAstTreeUtil.toPsi(astNode);
|
||||
if (psiElement instanceof PsiWhileStatement whileStatement) {
|
||||
final Document doc = editor.getDocument();
|
||||
final PsiJavaToken rParenth = whileStatement.getRParenth();
|
||||
final PsiJavaToken lParenth = whileStatement.getLParenth();
|
||||
final PsiExpression condition = whileStatement.getCondition();
|
||||
|
||||
if (condition == null) {
|
||||
if (lParenth == null || rParenth == null) {
|
||||
int stopOffset = doc.getLineEndOffset(doc.getLineNumber(whileStatement.getTextRange().getStartOffset()));
|
||||
final PsiStatement block = whileStatement.getBody();
|
||||
if (block != null) {
|
||||
stopOffset = Math.min(stopOffset, block.getTextRange().getStartOffset());
|
||||
}
|
||||
stopOffset = Math.min(stopOffset, whileStatement.getTextRange().getEndOffset());
|
||||
|
||||
doc.replaceString(whileStatement.getTextRange().getStartOffset(), stopOffset, "while ()");
|
||||
processor.registerUnresolvedError(whileStatement.getTextRange().getStartOffset() + "while (".length());
|
||||
} else {
|
||||
processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset());
|
||||
}
|
||||
} else if (rParenth == null) {
|
||||
doc.insertString(condition.getTextRange().getEndOffset(), ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class Foo {
|
||||
{
|
||||
while(true<caret>)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
class Foo {
|
||||
{
|
||||
while (true) {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user