clang-format: [Java] Support enums without trailing semicolon.
authorDaniel Jasper <djasper@google.com>
Sun, 2 Nov 2014 22:31:39 +0000 (22:31 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 2 Nov 2014 22:31:39 +0000 (22:31 +0000)
Before:
  class SomeClass {
    enum SomeThing { ABC, CDE } void f() {
    }
  }

After:
  class SomeClass {
    enum SomeThing { ABC, CDE }
    void f() {
    }
  }

This fixed llvm.org/PR21458.

llvm-svn: 221113

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestJava.cpp

index aa1bfdc..7d54156 100644 (file)
@@ -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() {
index 126b163..96dda9b 100644 (file)
@@ -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}");