From b9b6730b80a16798da559f2d50112cec3d8538ad Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 29 May 2024 09:28:19 -0700 Subject: [PATCH] Handle classes with no members and semi-colons PiperOrigin-RevId: 638312117 --- .../google/googlejavaformat/java/JavaInputAstVisitor.java | 6 ++++++ .../googlejavaformat/java/testdata/SemicolonInClass.input | 3 +++ .../googlejavaformat/java/testdata/SemicolonInClass.output | 3 +++ 3 files changed, 12 insertions(+) create mode 100644 core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.input create mode 100644 core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.output diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index 1e0675ffd..e00877e96 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -3744,6 +3744,12 @@ protected void addBodyDeclarations( tokenBreakTrailingComment("{", plusTwo); builder.blankLineWanted(BlankLineWanted.NO); builder.open(ZERO); + if (builder.peekToken().equals(Optional.of(";"))) { + builder.open(plusTwo); + dropEmptyDeclarations(); + builder.close(); + builder.forcedBreak(); + } token("}", plusTwo); builder.close(); } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.input new file mode 100644 index 000000000..52d3c1226 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.input @@ -0,0 +1,3 @@ +class SemicolonInClass { + ; +} diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.output new file mode 100644 index 000000000..52d3c1226 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/SemicolonInClass.output @@ -0,0 +1,3 @@ +class SemicolonInClass { + ; +}