r209615 - clang-format: Keep '{' of dict literals on the same line in Allman style

Daniel Jasper djasper at google.com
Mon May 26 00:24:34 PDT 2014


Author: djasper
Date: Mon May 26 02:24:34 2014
New Revision: 209615

URL: http://llvm.org/viewvc/llvm-project?rev=209615&view=rev
Log:
clang-format: Keep '{' of dict literals on the same line in Allman style

Before:
  void f()
  {
    [object
        someMethod:@
        { @"a" : @"b" }];
  }

After:
  void f()
  {
    [object someMethod:@{ @"a" : @"b" }];
  }

This fixes llvm.org/PR19854.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=209615&r1=209614&r2=209615&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May 26 02:24:34 2014
@@ -1596,7 +1596,7 @@ bool TokenAnnotator::mustBreakBefore(con
              !Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {
     return true;
   } else if (Right.is(tok::l_brace) && Right.BlockKind == BK_Block &&
-             Right.Type != TT_ObjCBlockLBrace) {
+             Right.Type != TT_ObjCBlockLBrace && Right.Type != TT_DictLiteral) {
     return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
            Style.BreakBeforeBraces == FormatStyle::BS_GNU;
   } else if (Right.is(tok::string_literal) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=209615&r1=209614&r2=209615&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon May 26 02:24:34 2014
@@ -7698,15 +7698,23 @@ TEST_F(FormatTest, AllmanBraceBreaking)
                "#endif",
                BreakBeforeBrace);
 
-  // This shouldn't affect ObjC blocks.
+  // This shouldn't affect ObjC blocks..
   verifyFormat("[self doSomeThingWithACompletionHandler:^{\n"
                "    // ...\n"
                "    int i;\n"
-               "}];");
+               "}];",
+               BreakBeforeBrace);
   verifyFormat("void (^block)(void) = ^{\n"
                "    // ...\n"
                "    int i;\n"
-               "};");
+               "};",
+               BreakBeforeBrace);
+  // .. or dict literals.
+  verifyFormat("void f()\n"
+               "{\n"
+               "  [object someMethod:@{ @\"a\" : @\"b\" }];\n"
+               "}",
+               BreakBeforeBrace);
 
   BreakBeforeBrace.ColumnLimit = 19;
   verifyFormat("void f() { int i; }", BreakBeforeBrace);





More information about the cfe-commits mailing list