Skip to content

Commit

Permalink
Fix missing parens for (string + string).contains(...) (#6094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 authored Dec 11, 2024
1 parent a1acd7b commit 2cf9fb2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private boolean shouldSetBracketAroundExpressionAndCast(CtExpression<?> e) {
return requiresBrackets == RoundBracketAnalyzer.EncloseInRoundBrackets.YES || !e.getTypeCasts().isEmpty();
}
if (e.isParentInitialized() && e.getParent() instanceof CtTargetedExpression && ((CtTargetedExpression) e.getParent()).getTarget() == e) {
return e instanceof CtVariableRead<?> && !e.getTypeCasts().isEmpty();
return e instanceof CtVariableRead<?> && !e.getTypeCasts().isEmpty() || e instanceof CtBinaryOperator<?>;
}
} else if (!e.getTypeCasts().isEmpty()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class DefaultJavaPrettyPrinterTest {
"(1 | 2) ^ 3",
"((int) (1 + 2)) * 3",
"(int) (int) (1 + 1)",
"(\"1\" + \"2\").contains(\"1\")",
})
public void testParenOptimizationCorrectlyPrintsParenthesesForExpressions(String rawExpression) {
// contract: When input expressions are minimally parenthesized, pretty-printed output
Expand Down

0 comments on commit 2cf9fb2

Please sign in to comment.