From: Daniel Jasper Date: Thu, 16 Jul 2015 14:25:43 +0000 (+0000) Subject: clang-format: [Proto] Handle enum bodies differently. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d04e4b6afa6f4b31bd0c45d2c748a1d6917657ff;p=clang clang-format: [Proto] Handle enum bodies differently. In proto, enum constants can contain complex options and should be handled more like individual declarations. Before: enum Type { UNKNOWN = 0 [(some_options) = { a: aa, b: bb }]; }; After: enum Type { UNKNOWN = 0 [(some_options) = { a: aa, b: bb }]; }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242404 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 97fd98ecb9..e705c98c67 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -811,9 +811,8 @@ void UnwrappedLineParser::parseStructuralElement() { // parseEnum falls through and does not yet add an unwrapped line as an // enum definition can start a structural element. parseEnum(); - // This does not apply for Java and JavaScript. - if (Style.Language == FormatStyle::LK_Java || - Style.Language == FormatStyle::LK_JavaScript) { + // This only applies for C++. + if (Style.Language != FormatStyle::LK_Cpp) { addUnwrappedLine(); return; } @@ -1554,6 +1553,9 @@ void UnwrappedLineParser::parseEnum() { // Java enums are different. parseJavaEnumBody(); return; + } else if (Style.Language == FormatStyle::LK_Proto) { + parseBlock(/*MustBeDeclaration=*/true); + return; } // Parse enum body. diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index 74f7005b21..0dadd3b673 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -73,6 +73,12 @@ TEST_F(FormatTestProto, FormatsEnums) { " TYPE_A = 1;\n" " TYPE_B = 2;\n" "};"); + verifyFormat("enum Type {\n" + " UNKNOWN = 0 [(some_options) = {\n" + " a: aa,\n" + " b: bb\n" + " }];\n" + "};"); } TEST_F(FormatTestProto, UnderstandsReturns) {