From: Daniel Jasper Date: Sun, 2 Nov 2014 22:31:39 +0000 (+0000) Subject: clang-format: [Java] Support enums without trailing semicolon. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7909991216e90e2dc7e0c72952f7d0fd94e9aac0;p=clang clang-format: [Java] Support enums without trailing semicolon. Before: class SomeClass { enum SomeThing { ABC, CDE } void f() { } } After: class SomeClass { enum SomeThing { ABC, CDE } void f() { } } This fixed llvm.org/PR21458. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221113 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index aa1bfdc725..7d54156c3b 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1362,6 +1362,9 @@ void UnwrappedLineParser::parseEnum() { // We fall through to parsing a structural element afterwards, so that in // enum A {} n, m; // "} n, m;" will end up in one unwrapped line. + // This does not apply for Java. + if (Style.Language == FormatStyle::LK_Java) + addUnwrappedLine(); } void UnwrappedLineParser::parseRecord() { diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 126b163c60..96dda9b11b 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -79,6 +79,19 @@ TEST_F(FormatTestJava, ClassDeclarations) { getStyleWithColumns(40)); } +TEST_F(FormatTestJava, EnumDeclarations) { + verifyFormat("enum SomeThing { ABC, CDE }"); + verifyFormat("enum SomeThing {\n" + " ABC,\n" + " CDE,\n" + "}"); + verifyFormat("public class SomeClass {\n" + " enum SomeThing { ABC, CDE }\n" + " void f() {\n" + " }\n" + "}"); +} + TEST_F(FormatTestJava, ThrowsDeclarations) { verifyFormat("public void doSooooooooooooooooooooooooooomething()\n" " throws LooooooooooooooooooooooooooooongException {\n}");