File tree Expand file tree Collapse file tree 7 files changed +35
-1
lines changed
packages/prettier-plugin-java Expand file tree Collapse file tree 7 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -374,13 +374,18 @@ export default {
374374 const expression = call ( path , print , "expression" ) ;
375375 const ancestorName = ( path . getNode ( 14 ) as JavaNonTerminal | null ) ?. name ;
376376 const binaryExpression = path . getNode ( 8 ) as JavaNonTerminal | null ;
377+ const { conditionalExpression, lambdaExpression } =
378+ path . node . children . expression [ 0 ] . children ;
379+ const hasLambda = lambdaExpression !== undefined ;
380+ const hasTernary =
381+ conditionalExpression ?. [ 0 ] . children . QuestionMark !== undefined ;
377382 return ancestorName &&
378383 [ "guard" , "returnStatement" ] . includes ( ancestorName ) &&
379384 binaryExpression &&
380385 binaryExpression . name === "binaryExpression" &&
381386 Object . keys ( binaryExpression . children ) . length === 1
382387 ? indentInParentheses ( expression )
383- : [ "(" , indent ( expression ) , ")" ] ;
388+ : [ "(" , hasLambda || hasTernary ? expression : indent ( expression ) , ")" ] ;
384389 } ,
385390
386391 castExpression : printSingle ,
Original file line number Diff line number Diff line change @@ -38,4 +38,8 @@ void ternaryWithComments() {
3838 ? b // b
3939 : c ; // c
4040 }
41+
42+ void ternaryInParentheses () {
43+ (aaaaaaaaaa ? bbbbbbbbbb : cccccccccc .dddddddddd ().eeeeeeeeee ().ffffffffff ());
44+ }
4145}
Original file line number Diff line number Diff line change @@ -53,4 +53,10 @@ void ternaryWithComments() {
5353 ? b // b
5454 : c ; // c
5555 }
56+
57+ void ternaryInParentheses () {
58+ (aaaaaaaaaa
59+ ? bbbbbbbbbb
60+ : cccccccccc .dddddddddd ().eeeeeeeeee ().ffffffffff ());
61+ }
5662}
Original file line number Diff line number Diff line change @@ -38,4 +38,8 @@ void ternaryWithComments() {
3838 ? b // b
3939 : c ; // c
4040 }
41+
42+ void ternaryInParentheses () {
43+ (aaaaaaaaaa ? bbbbbbbbbb : cccccccccc .dddddddddd ().eeeeeeeeee ().ffffffffff ());
44+ }
4145}
Original file line number Diff line number Diff line change @@ -52,4 +52,10 @@ void ternaryWithComments() {
5252 ? b // b
5353 : c ; // c
5454 }
55+
56+ void ternaryInParentheses () {
57+ (aaaaaaaaaa
58+ ? bbbbbbbbbb
59+ : cccccccccc .dddddddddd ().eeeeeeeeee ().ffffffffff ());
60+ }
5561}
Original file line number Diff line number Diff line change @@ -333,6 +333,10 @@ void lambdaWithTrailingComments() {
333333 ).collect (Collectors .summingInt (v -> v ))
334334 );
335335 }
336+
337+ void lambdaInParentheses () {
338+ (aaaaaaaaaa -> bbbbbbbbbb .cccccccccc ().dddddddddd ().eeeeeeeeee ().ffffffffff ());
339+ }
336340}
337341
338342class T {
Original file line number Diff line number Diff line change @@ -576,6 +576,11 @@ void lambdaWithTrailingComments() {
576576 .collect (Collectors .summingInt (v -> v ))
577577 );
578578 }
579+
580+ void lambdaInParentheses () {
581+ (aaaaaaaaaa ->
582+ bbbbbbbbbb .cccccccccc ().dddddddddd ().eeeeeeeeee ().ffffffffff ());
583+ }
579584}
580585
581586class T {
You can’t perform that action at this time.
0 commit comments