[java-completion] MissingThrowExpressionFixer: avoid completion if it's started on the expression line

Fixes IDEA-367667 Complete current statement action breaks on a new line character

GitOrigin-RevId: fed8b5d8d860f491391413383922c112d9649eff
This commit is contained in:
Tagir Valeev
2025-03-07 12:30:11 +01:00
committed by intellij-monorepo-bot
parent af80b1afd1
commit b8792b5e29
4 changed files with 20 additions and 3 deletions

View File

@@ -15,9 +15,10 @@ public class MissingThrowExpressionFixer implements Fixer {
throws IncorrectOperationException {
if (BasicJavaAstTreeUtil.is(astNode, BASIC_THROW_STATEMENT)) {
ASTNode expression = BasicJavaAstTreeUtil.getExpression(astNode);
if (expression != null &&
startLine(editor, astNode) == startLine(editor, expression)) {
return;
if (expression != null) {
int expressionLine = startLine(editor, expression);
if (startLine(editor, astNode) == expressionLine) return;
if (editor.getDocument().getLineNumber(editor.getCaretModel().getOffset()) == expressionLine) return;
}
final int startOffset = astNode.getTextRange().getStartOffset();

View File

@@ -85,6 +85,8 @@ public abstract class AbstractBasicCompleteStatementTest extends LightPlatformCo
public void testNoErrors() { doTest(); }
public void testThrow() { doTest(); }
public void testThrowTwoLinesSemicolon() { doTest(); }
public void testReturn() { doTest(); }

View File

@@ -0,0 +1,7 @@
class Scratch {
public static void main(String[] args) {
throw
new <caret>RuntimeException("aaa")
}
}

View File

@@ -0,0 +1,7 @@
class Scratch {
public static void main(String[] args) {
throw
new RuntimeException("aaa");
}
}