Java: more sensible parse of incomplete binary expression (IDEA-305898)

GitOrigin-RevId: 3d3b59be1621fea7a4702109e1d654b47c5c76f7
This commit is contained in:
Bas Leijdekkers
2024-08-01 12:35:28 +00:00
committed by intellij-monorepo-bot
parent bc91c92493
commit c8215f8fbc
5 changed files with 35 additions and 12 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.java.parser;
import com.intellij.core.JavaPsiBundle;
@@ -196,14 +196,14 @@ public class BasicOldExpressionParser {
advanceGtToken(builder, tokenType);
final PsiBuilder.Marker right = parseExpression(builder, type, mode);
if (right == null) {
error(builder, JavaPsiBundle.message("expected.expression"));
}
operandCount++;
tokenType = getGtTokenType(builder);
if (tokenType == null || !ops.contains(tokenType) || tokenType != currentExprTokenType || right == null) {
if (tokenType == null || !ops.contains(tokenType) || tokenType != currentExprTokenType) {
// save
result = result.precede();
if (right == null) {
error(builder, JavaPsiBundle.message("expected.expression"));
}
result.done(operandCount > 2 ? myJavaElementTypeContainer.POLYADIC_EXPRESSION : myJavaElementTypeContainer.BINARY_EXPRESSION);
if (right == null) break;
currentExprTokenType = tokenType;
@@ -1000,14 +1000,12 @@ public class BasicPrattExpressionParser {
while (true) {
advanceBinOpToken(builder, binOpType);
PsiBuilder.Marker rhs = parser.tryParseWithPrecedenceAtMost(builder, currentPrecedence - 1, mode);
IElementType nextToken = getBinOpToken(builder);
if (rhs != null) {
operandCount++;
if (rhs == null) {
error(builder, JavaPsiBundle.message("expected.expression"));
}
if (rhs == null || nextToken != binOpType) {
if (rhs == null) {
error(builder, JavaPsiBundle.message("expected.expression"));
}
operandCount++;
IElementType nextToken = getBinOpToken(builder);
if (nextToken != binOpType) {
break;
}
}