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 {
203
203
204
204
const elseOnSameLine =
205
205
hasTrailingLineComments ( ctx . statement [ 0 ] ) ||
206
- hasLeadingLineComments ( ctx . Else [ 0 ] )
206
+ hasLeadingLineComments ( ctx . Else [ 0 ] ) ||
207
+ ! ctx . statement [ 0 ] . children . statementWithoutTrailingSubstatement ?. [ 0 ]
208
+ . children . block
207
209
? hardline
208
210
: " " ;
209
211
Original file line number Diff line number Diff line change @@ -37,23 +37,27 @@ public void forEachWithEmptyStatement(List<String> list) {
37
37
}
38
38
39
39
public void ifElseWithEmptyStatements () {
40
- if (test ); else {
40
+ if (test );
41
+ else {
41
42
System .out .println ("one" );
42
43
}
43
44
44
45
if (test ) {
45
46
System .out .println ("two" );
46
47
} else ;
47
48
48
- if (test ); else ;
49
+ if (test );
50
+ else ;
49
51
}
50
52
51
53
public void ifElseWithEmptyStatementsWithComments () {
52
- if (test ) /*test*/ ; else {
54
+ if (test ) /*test*/ ;
55
+ else {
53
56
System .out .println ("one" );
54
57
}
55
58
56
- if (test ); /*test*/ else {
59
+ if (test );
60
+ /*test*/ else {
57
61
System .out .println ("one" );
58
62
}
59
63
@@ -65,9 +69,11 @@ public void ifElseWithEmptyStatementsWithComments() {
65
69
System .out .println ("two" );
66
70
} else ;/*test*/
67
71
68
- if (test ); /*test*/ else ;/*test*/
72
+ if (test );
73
+ /*test*/ else ;/*test*/
69
74
70
- if (test ) /*test*/ ; else /*test*/ ;
75
+ if (test ) /*test*/ ;
76
+ else /*test*/ ;
71
77
}
72
78
73
79
public void simpleWhileWithEmptyStatement (boolean one ) {
Original file line number Diff line number Diff line change @@ -46,11 +46,9 @@ default Shape rotate(double angle) {
46
46
}
47
47
48
48
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 ();
54
52
// :(
55
53
throw new IllegalArgumentException ();
56
54
}
You can’t perform that action at this time.
0 commit comments