diff --git a/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java index 28a110395..6585c6f6e 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java @@ -223,7 +223,7 @@ public Void visitCase(CaseTree node, Void unused) { token(">"); builder.space(); scan(node.getBody(), null); - token(";"); + builder.guessToken(";"); break; default: throw new AssertionError(node.getCaseKind()); diff --git a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java index 289ea1baf..0e0ab9f49 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java @@ -47,7 +47,7 @@ @RunWith(Parameterized.class) public class FormatterIntegrationTest { - private static final ImmutableSet JAVA14_TESTS = ImmutableSet.of("java14"); + private static final ImmutableSet JAVA14_TESTS = ImmutableSet.of("java14", "I477"); @Parameters(name = "{index}: {0}") public static Iterable data() throws IOException { diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I477.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I477.input new file mode 100644 index 000000000..ecd8658b3 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I477.input @@ -0,0 +1,17 @@ +class I477 { + public static String foo(int in) { + return switch (in) { + case 1 -> "A"; + case 2 -> "B"; + default -> throw new IllegalStateException("Unknown input " + in); + }; + } + + public static String foo(int in) { + return switch (in) { + case 1 -> "A"; + case 2 -> "B"; + default -> "C"; + }; + } +} diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I477.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I477.output new file mode 100644 index 000000000..ecd8658b3 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I477.output @@ -0,0 +1,17 @@ +class I477 { + public static String foo(int in) { + return switch (in) { + case 1 -> "A"; + case 2 -> "B"; + default -> throw new IllegalStateException("Unknown input " + in); + }; + } + + public static String foo(int in) { + return switch (in) { + case 1 -> "A"; + case 2 -> "B"; + default -> "C"; + }; + } +}