r296499 - clang-format: [Java] Fix bug in enum formatting.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 28 10:28:15 PST 2017


Author: djasper
Date: Tue Feb 28 12:28:15 2017
New Revision: 296499

URL: http://llvm.org/viewvc/llvm-project?rev=296499&view=rev
Log:
clang-format: [Java] Fix bug in enum formatting.

Before:
  public enum VeryLongEnum {
    ENUM_WITH_MANY_PARAMETERS("aaaaaaaaaaaaaaaaaaaaaa",
                              "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
                              "ccccccccccccccccccc")
    ,
    SECOND_ENUM("a", "b", "c");

    private VeryLongEnum(String a, String b, String c) {}
  }

After:
  public enum VeryLongEnum {
    ENUM_WITH_MANY_PARAMETERS("aaaaaaaaaaaaaaaaaaaaaa",
                              "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
                              "ccccccccccccccccccc") ,
    SECOND_ENUM("a", "b", "c");

    private VeryLongEnum(String a, String b, String c) {}
  }

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJava.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=296499&r1=296498&r2=296499&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 28 12:28:15 2017
@@ -1083,7 +1083,8 @@ private:
       if (Current.MatchingParen && Current.Next &&
           !Current.Next->isBinaryOperator() &&
           !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
-                                 tok::period, tok::arrow, tok::coloncolon))
+                                 tok::comma, tok::period, tok::arrow,
+                                 tok::coloncolon))
         if (FormatToken *AfterParen = Current.MatchingParen->Next) {
           // Make sure this isn't the return type of an Obj-C block declaration
           if (AfterParen->Tok.isNot(tok::caret)) {

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=296499&r1=296498&r2=296499&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Tue Feb 28 12:28:15 2017
@@ -225,6 +225,13 @@ TEST_F(FormatTestJava, EnumDeclarations)
                "    }\n"
                "  };\n"
                "}");
+  verifyFormat("public enum VeryLongEnum {\n"
+               "  ENUM_WITH_MANY_PARAMETERS(\n"
+               "      \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"bbbbbbbbbbbbbbbb\", "
+               "\"cccccccccccccccccccccccc\"),\n"
+               "  SECOND_ENUM(\"a\", \"b\", \"c\");\n"
+               "  private VeryLongEnum(String a, String b, String c) {}\n"
+               "}\n");
 }
 
 TEST_F(FormatTestJava, ArrayInitializers) {




More information about the cfe-commits mailing list