File tree Expand file tree Collapse file tree 3 files changed +18
-12
lines changed
packages/prettier-plugin-java Expand file tree Collapse file tree 3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -203,7 +203,9 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter {
203203
204204 const elseOnSameLine =
205205 hasTrailingLineComments ( ctx . statement [ 0 ] ) ||
206- hasLeadingLineComments ( ctx . Else [ 0 ] )
206+ hasLeadingLineComments ( ctx . Else [ 0 ] ) ||
207+ ! ctx . statement [ 0 ] . children . statementWithoutTrailingSubstatement ?. [ 0 ]
208+ . children . block
207209 ? hardline
208210 : " " ;
209211
Original file line number Diff line number Diff line change @@ -37,23 +37,27 @@ public void forEachWithEmptyStatement(List<String> list) {
3737 }
3838
3939 public void ifElseWithEmptyStatements () {
40- if (test ); else {
40+ if (test );
41+ else {
4142 System .out .println ("one" );
4243 }
4344
4445 if (test ) {
4546 System .out .println ("two" );
4647 } else ;
4748
48- if (test ); else ;
49+ if (test );
50+ else ;
4951 }
5052
5153 public void ifElseWithEmptyStatementsWithComments () {
52- if (test ) /*test*/ ; else {
54+ if (test ) /*test*/ ;
55+ else {
5356 System .out .println ("one" );
5457 }
5558
56- if (test ); /*test*/ else {
59+ if (test );
60+ /*test*/ else {
5761 System .out .println ("one" );
5862 }
5963
@@ -65,9 +69,11 @@ public void ifElseWithEmptyStatementsWithComments() {
6569 System .out .println ("two" );
6670 } else ;/*test*/
6771
68- if (test ); /*test*/ else ;/*test*/
72+ if (test );
73+ /*test*/ else ;/*test*/
6974
70- if (test ) /*test*/ ; else /*test*/ ;
75+ if (test ) /*test*/ ;
76+ else /*test*/ ;
7177 }
7278
7379 public void simpleWhileWithEmptyStatement (boolean one ) {
Original file line number Diff line number Diff line change @@ -46,11 +46,9 @@ default Shape rotate(double angle) {
4646 }
4747
4848 default String areaMessage () {
49- if (this instanceof Circle ) return "Circle: " + area (); else if (
50- this instanceof Rectangle
51- ) return "Rectangle: " + area (); else if (
52- this instanceof RightTriangle
53- ) return "Triangle: " + area ();
49+ if (this instanceof Circle ) return "Circle: " + area ();
50+ else if (this instanceof Rectangle ) return "Rectangle: " + area ();
51+ else if (this instanceof RightTriangle ) return "Triangle: " + area ();
5452 // :(
5553 throw new IllegalArgumentException ();
5654 }
You can’t perform that action at this time.
0 commit comments