ParenthesesUtils#removeParensFromPolyadicExpression: check operand validity

As processing the previous operands may completely rewrite the whole polyadic expression, we have to stop if this happens
No need to find the replacement and process the tail: it's already processed in removeParensFromParenthesizedExpression
Fixes EA-141996 - PIEAE: CompositePsiElement.getContainingFile

GitOrigin-RevId: 64162346a612e2d95eec426419bef51d6c5d46a3
This commit is contained in:
Tagir Valeev
2019-04-26 12:25:41 +07:00
committed by intellij-monorepo-bot
parent a732bb2039
commit 3368f8e2d5
3 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
// "Simplify boolean expression" "true"
class X {
void test(int a, int b) {
if (a + 1 + foo(a, b) > 5) {
}
}
private int foo(int a, int b) {
return a+b;
}
}

View File

@@ -0,0 +1,13 @@
// "Simplify boolean expression" "true"
class X {
void test(int a, int b) {
if (<caret>true && (a + 1) + foo((a), b) > 5) {
}
}
private int foo(int a, int b) {
return a+b;
}
}

View File

@@ -219,6 +219,7 @@ public class ParenthesesUtils {
private static void removeParensFromPolyadicExpression(@NotNull PsiPolyadicExpression polyadicExpression,
boolean ignoreClarifyingParentheses) {
for (PsiExpression operand : polyadicExpression.getOperands()) {
if (!operand.isValid()) break;
removeParentheses(operand, ignoreClarifyingParentheses);
}
}