]> granicus.if.org Git - clang/commitdiff
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221113 91177308-0d34-0410-b5e6-96231b3b80d8

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

index aa1bfdc725ef50e2763e3c8ea8d9489e181bad35..7d54156c3bc0c79b810809fc371563e17d0e7e23 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 126b163c6008d2db7f0926c2351a186f85ed4752..96dda9b11b47bd2ea6826deb0fb6d6c26f819301 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}");