This revision was automatically updated to reflect the committed changes.
Closed by commit rL307261: [clang-format] Add space between a message field key 
and the opening bracket in… (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D35015

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2301,6 +2301,8 @@
     if (Right.is(tok::l_paren) &&
         Left.isOneOf(Keywords.kw_returns, Keywords.kw_option))
       return true;
+    if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName))
+      return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
     if (Left.is(TT_JsFatArrow))
       return true;
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -199,11 +199,11 @@
                "};");
   verifyFormat("option (MyProto.options) = {\n"
                "  field_c: \"OK\"\n"
-               "  msg_field{field_d: 123}\n"
+               "  msg_field {field_d: 123}\n"
                "};");
   verifyFormat("option (MyProto.options) = {\n"
                "  field_a: OK\n"
-               "  field_b{field_c: OK}\n"
+               "  field_b {field_c: OK}\n"
                "  field_d: OKOKOK\n"
                "  field_e: OK\n"
                "}");
@@ -216,7 +216,7 @@
 
   verifyFormat("option (MyProto.options) = {\n"
                "  field_a: OK\n"
-               "  field_b<field_c: OK>\n"
+               "  field_b <field_c: OK>\n"
                "  field_d: OKOKOK\n"
                "  field_e: OK\n"
                "}");
@@ -255,7 +255,7 @@
 
   verifyFormat("option (MyProto.options) = <\n"
                "  field_a: \"OK\"\n"
-               "  msg_field<\n"
+               "  msg_field <\n"
                "    field_b: OK\n"
                "    field_c: OK\n"
                "    field_d: OK\n"
@@ -267,7 +267,7 @@
 
   verifyFormat("option (MyProto.options) = <\n"
                "  field_a: \"OK\"\n"
-               "  msg_field<\n"
+               "  msg_field <\n"
                "    field_b: OK,\n"
                "    field_c: OK,\n"
                "    field_d: OK,\n"
@@ -303,7 +303,7 @@
 
   verifyFormat("option (MyProto.options) = <\n"
                "  field_a: \"OK\"\n"
-               "  msg_field{\n"
+               "  msg_field {\n"
                "    field_b: OK\n"
                "    field_c: OK\n"
                "    field_d: OK\n"
@@ -315,7 +315,7 @@
 
   verifyFormat("option (MyProto.options) = {\n"
                "  field_a: \"OK\"\n"
-               "  msg_field<\n"
+               "  msg_field <\n"
                "    field_b: OK\n"
                "    field_c: OK\n"
                "    field_d: OK\n"
@@ -339,18 +339,18 @@
 
   verifyFormat("option (MyProto.options) = <\n"
                "  field_a: \"OK\"\n"
-               "  msg_field{\n"
+               "  msg_field {\n"
                "    field_b: OK\n"
                "    field_c: OK\n"
                "    field_d: OK\n"
-               "    msg_field<\n"
+               "    msg_field <\n"
                "      field_A: 1\n"
                "      field_B: 2\n"
                "      field_C: 3\n"
                "      field_D: 4\n"
                "      field_E: 5\n"
                "    >\n"
-               "    msg_field<field_A: 1 field_B: 2 field_C: 3 field_D: 4>\n"
+               "    msg_field <field_A: 1 field_B: 2 field_C: 3 field_D: 4>\n"
                "    field_e: OK\n"
                "    field_f: OK\n"
                "  }\n"
Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -61,13 +61,13 @@
                "  field_e: 23\n"
                "}");
 
-  verifyFormat("msg_field{}");
+  verifyFormat("msg_field {}");
 
-  verifyFormat("msg_field{field_a: A}");
+  verifyFormat("msg_field {field_a: A}");
 
-  verifyFormat("msg_field{field_a: \"OK\" field_b: 123}");
+  verifyFormat("msg_field {field_a: \"OK\" field_b: 123}");
 
-  verifyFormat("msg_field{\n"
+  verifyFormat("msg_field {\n"
                "  field_a: 1\n"
                "  field_b: OK\n"
                "  field_c: \"OK\"\n"
@@ -78,12 +78,12 @@
                "  field_h: 1234.567e-89\n"
                "}");
 
-  verifyFormat("msg_field: {msg_field{field_a: 1}}");
+  verifyFormat("msg_field: {msg_field {field_a: 1}}");
 
   verifyFormat("id: \"ala.bala\"\n"
-               "item{type: ITEM_A rank: 1 score: 90.0}\n"
-               "item{type: ITEM_B rank: 2 score: 70.5}\n"
-               "item{\n"
+               "item {type: ITEM_A rank: 1 score: 90.0}\n"
+               "item {type: ITEM_B rank: 2 score: 70.5}\n"
+               "item {\n"
                "  type: ITEM_A\n"
                "  rank: 3\n"
                "  score: 20.0\n"
@@ -113,13 +113,13 @@
 
   verifyFormat("a: {\n"
                "  field_a: OK\n"
-               "  field_b{field_c: OK}\n"
+               "  field_b {field_c: OK}\n"
                "  field_d: OKOKOK\n"
                "  field_e: OK\n"
                "}");
 
   verifyFormat("field_a: OK,\n"
-               "field_b{field_c: OK},\n"
+               "field_b {field_c: OK},\n"
                "field_d: OKOKOK,\n"
                "field_e: OK");
 }
@@ -134,33 +134,33 @@
                "}");
 
   verifyFormat("field_a: OK\n"
-               "msg_field{\n"
+               "msg_field {\n"
                "  field_b: OK  // Comment\n"
                "}");
 }
 
 TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
   // Single-line tests
-  verifyFormat("msg_field<>");
+  verifyFormat("msg_field <>");
   verifyFormat("msg_field: <>");
-  verifyFormat("msg_field<field_a: OK>");
+  verifyFormat("msg_field <field_a: OK>");
   verifyFormat("msg_field: <field_a: 123>");
-  verifyFormat("msg_field<field_a<>>");
-  verifyFormat("msg_field<field_a<field_b<>>>");
-  verifyFormat("msg_field: <field_a<field_b: <>>>");
-  verifyFormat("msg_field<field_a: OK, field_b: \"OK\">");
-  verifyFormat("msg_field<field_a: OK field_b: <>, field_c: OK>");
-  verifyFormat("msg_field<field_a{field_b: 1}, field_c: <field_d: 2>>");
+  verifyFormat("msg_field <field_a <>>");
+  verifyFormat("msg_field <field_a <field_b <>>>");
+  verifyFormat("msg_field: <field_a <field_b: <>>>");
+  verifyFormat("msg_field <field_a: OK, field_b: \"OK\">");
+  verifyFormat("msg_field <field_a: OK field_b: <>, field_c: OK>");
+  verifyFormat("msg_field <field_a {field_b: 1}, field_c: <field_d: 2>>");
   verifyFormat("msg_field: <field_a: OK, field_b: \"OK\">");
   verifyFormat("msg_field: <field_a: OK field_b: <>, field_c: OK>");
-  verifyFormat("msg_field: <field_a{field_b: 1}, field_c: <field_d: 2>>");
+  verifyFormat("msg_field: <field_a {field_b: 1}, field_c: <field_d: 2>>");
   verifyFormat("field_a: \"OK\", msg_field: <field_b: 123>, field_c: {}");
-  verifyFormat("field_a<field_b: 1>, msg_field: <field_b: 123>, field_c<>");
-  verifyFormat("field_a<field_b: 1> msg_field: <field_b: 123> field_c<>");
-  verifyFormat("field<field<field: <>>, field<>> field: <field: 1>");
+  verifyFormat("field_a <field_b: 1>, msg_field: <field_b: 123>, field_c <>");
+  verifyFormat("field_a <field_b: 1> msg_field: <field_b: 123> field_c <>");
+  verifyFormat("field <field <field: <>>, field <>> field: <field: 1>");
 
   // Multiple lines tests
-  verifyFormat("msg_field<\n"
+  verifyFormat("msg_field <\n"
                "  field_a: OK\n"
                "  field_b: \"OK\"\n"
                "  field_c: 1\n"
@@ -175,25 +175,25 @@
                "msg_field: <field_d: 12>");
 
   verifyFormat("field_a: OK,\n"
-               "field_b<field_c: OK>,\n"
+               "field_b <field_c: OK>,\n"
                "field_d: <12.5>,\n"
                "field_e: OK");
 
   verifyFormat("field_a: OK\n"
-               "field_b<field_c: OK>\n"
+               "field_b <field_c: OK>\n"
                "field_d: <12.5>\n"
                "field_e: OKOKOK");
 
-  verifyFormat("msg_field<\n"
+  verifyFormat("msg_field <\n"
                "  field_a: OK,\n"
-               "  field_b<field_c: OK>,\n"
+               "  field_b <field_c: OK>,\n"
                "  field_d: <12.5>,\n"
                "  field_e: OK\n"
                ">");
 
-  verifyFormat("msg_field<\n"
+  verifyFormat("msg_field <\n"
                "  field_a: <field: OK>,\n"
-               "  field_b<field_c: OK>,\n"
+               "  field_b <field_c: OK>,\n"
                "  field_d: <12.5>,\n"
                "  field_e: OK,\n"
                ">");
@@ -206,7 +206,7 @@
                "  field_g: OK\n"
                ">");
 
-  verifyFormat("field_a{\n"
+  verifyFormat("field_a {\n"
                "  field_d: ok\n"
                "  field_b: <field_c: 1>\n"
                "  field_d: ok\n"
@@ -221,16 +221,16 @@
                "}");
 
   verifyFormat("field_a: <f1: 1, f2: <>>\n"
-               "field_b<\n"
+               "field_b <\n"
                "  field_b1: <>\n"
                "  field_b2: ok,\n"
                "  field_b3: <\n"
-               "    field_x{}  // Comment\n"
+               "    field_x {}  // Comment\n"
                "    field_y: {field_z: 1}\n"
                "    field_w: ok\n"
                "  >\n"
-               "  field{\n"
-               "    field_x<>  // Comment\n"
+               "  field {\n"
+               "    field_x <>  // Comment\n"
                "    field_y: <field_z: 1>\n"
                "    field_w: ok\n"
                "    msg_field: <\n"
@@ -244,8 +244,7 @@
                "  }\n"
                ">\n"
                "field: OK,\n"
-               "field_c<field<field<>>>");
+               "field_c <field <field <>>>");
 }
-
 } // end namespace tooling
 } // end namespace clang
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to