File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed
packages/prettier-plugin-java Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -265,13 +265,20 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter {
265
265
266
266
switchBlockStatementGroup ( ctx : SwitchBlockStatementGroupCtx ) {
267
267
const switchLabel = this . visit ( ctx . switchLabel ) ;
268
-
269
268
const blockStatements = this . visit ( ctx . blockStatements ) ;
270
269
270
+ const statements = ctx . blockStatements ?. [ 0 ] . children . blockStatement ;
271
+ const hasSingleStatementBlock =
272
+ statements ?. length === 1 &&
273
+ statements [ 0 ] . children . statement ?. [ 0 ] . children
274
+ . statementWithoutTrailingSubstatement ?. [ 0 ] . children . block !== undefined ;
275
+
271
276
return concat ( [
272
277
switchLabel ,
273
278
ctx . Colon [ 0 ] ,
274
- blockStatements && indent ( [ hardline , blockStatements ] )
279
+ hasSingleStatementBlock
280
+ ? concat ( [ " " , blockStatements ] )
281
+ : blockStatements && indent ( [ hardline , blockStatements ] )
275
282
] ) ;
276
283
}
277
284
Original file line number Diff line number Diff line change @@ -48,6 +48,16 @@ public String shouldWrapEvenForSmallSwitchCases() {
48
48
switch (answer ) { case "YES" : return "YES" ; default : return "NO" ; }
49
49
}
50
50
51
+ void switchCaseWithBlock () {
52
+ switch (a ) {
53
+ case 1 : {}
54
+ case 2 : { b (); }
55
+ case 3 : { c (); } { d (); }
56
+ case 4 : e (); { f (); }
57
+ case 5 : { g (); } h ();
58
+ }
59
+ }
60
+
51
61
// Switch rules
52
62
static void howManyAgain (int k ) {
53
63
switch (k ) {
Original file line number Diff line number Diff line change @@ -53,6 +53,32 @@ public String shouldWrapEvenForSmallSwitchCases() {
53
53
}
54
54
}
55
55
56
+ void switchCaseWithBlock () {
57
+ switch (a ) {
58
+ case 1 : {}
59
+ case 2 : {
60
+ b ();
61
+ }
62
+ case 3 :
63
+ {
64
+ c ();
65
+ }
66
+ {
67
+ d ();
68
+ }
69
+ case 4 :
70
+ e ();
71
+ {
72
+ f ();
73
+ }
74
+ case 5 :
75
+ {
76
+ g ();
77
+ }
78
+ h ();
79
+ }
80
+ }
81
+
56
82
// Switch rules
57
83
static void howManyAgain (int k ) {
58
84
switch (k ) {
You can’t perform that action at this time.
0 commit comments