]> granicus.if.org Git - clang/commitdiff
clang-format: Keep '{' of dict literals on the same line in Allman style
authorDaniel Jasper <djasper@google.com>
Mon, 26 May 2014 07:24:34 +0000 (07:24 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 26 May 2014 07:24:34 +0000 (07:24 +0000)
Before:
  void f()
  {
    [object
        someMethod:@
        { @"a" : @"b" }];
  }

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

This fixes llvm.org/PR19854.

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index f057ef7f3e740475471ae8ceacb77bc0659e7c04..3fea52b9f8af86c177259f9fc114a0c50307cc4a 100644 (file)
@@ -1596,7 +1596,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
              !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) &&
index 9cf4efcbf1ff870fd1649356885242d698eda1dc..94d4bbb00ef0c8b0a073a8345ad561f5e8313574 100644 (file)
@@ -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);