diff --git a/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts b/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts index 8b7cda35..023e1d09 100644 --- a/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts +++ b/packages/prettier-plugin-java/src/printers/blocks-and-statements.ts @@ -175,7 +175,7 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { const identifier = ctx.Identifier[0]; const statement = this.visit(ctx.statement); - return rejectAndJoin(ctx.Colon[0], [identifier, statement]); + return concat([identifier, ctx.Colon[0], " ", statement]); } expressionStatement(ctx: ExpressionStatementCtx) { diff --git a/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/complex/_output.java b/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/complex/_output.java index 8d0a1a1e..c6cb6b88 100644 --- a/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/complex/_output.java +++ b/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/complex/_output.java @@ -43,7 +43,7 @@ private void myFunction( // Label statement //foreach - loop:for (int num /* num is every number in arr*/: arr) { + loop: for (int num /* num is every number in arr*/: arr) { /*switch*/switch (num) { //switch case 1: System.out.println("One "); diff --git a/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_input.java b/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_input.java index 48edfb67..9b46a53d 100644 --- a/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_input.java +++ b/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_input.java @@ -140,5 +140,10 @@ void commentsLabeledStatementMixedComment() { for (int num : arr) { } } -} + void labeledBlockStatement() { + label:{ + example(); + } + } +} diff --git a/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_output.java b/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_output.java index a114fea2..d2c5ec58 100644 --- a/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_output.java +++ b/packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/labeled-statement/_output.java @@ -3,104 +3,110 @@ class LabeledStatements { void commentsLabeledStatementLineComment() { // Label statement // comment1 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // Label statement // comment1 // comment2 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // Label statement // comment1 // comment2 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // comment1 // comment2 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // comment1 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // comment1 - loop:for (int num : arr) {} + loop: for (int num : arr) {} - loop:for (int num : arr) {} + loop: for (int num : arr) {} } void commentsLabeledStatementBlockComment() { /* Label statement */ /* comment1 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* Label statement */ /* comment1 */ /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* Label statement */ /* comment1 */ /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* comment1 */ /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* comment1 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* comment1 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} - loop:for (int num : arr) {} + loop: for (int num : arr) {} } void commentsLabeledStatementMixedComment() { // Label statement /* comment1 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* Label statement */ // comment1 - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* Label statement */ // comment1 // comment2 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // Label statement /* comment1 */ // comment2 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // Label statement // comment1 /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* Label statement */ // comment1 /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} // Label statement /* comment1 */ /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* Label statement */ /* comment1 */ // comment2 - loop:for (int num : arr) {} + loop: for (int num : arr) {} // comment1 /* comment2 */ - loop:for (int num : arr) {} + loop: for (int num : arr) {} /* comment1 */ // comment2 - oop:for (int num : arr) {} + oop: for (int num : arr) {} + } + + void labeledBlockStatement() { + label: { + example(); + } } }