]> granicus.if.org Git - clang/commitdiff
clang-format: Indent from dict literal labels.
authorDaniel Jasper <djasper@google.com>
Mon, 17 Mar 2014 14:32:47 +0000 (14:32 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 17 Mar 2014 14:32:47 +0000 (14:32 +0000)
Before:
  @{
    NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
    regularFont,
  };

After:
  @{
    NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
        regularFont,
  };

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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index 17af2fa5f2520d555105a0e28a14a0449e9e0a22..380532a47cc2b26b65840e97bbde871e4949aff8 100644 (file)
@@ -426,8 +426,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
   } else if (NextNonComment->Type == TT_StartOfName ||
              Previous.isOneOf(tok::coloncolon, tok::equal)) {
     State.Column = ContinuationIndent;
-  } else if (PreviousNonComment &&
-             PreviousNonComment->Type == TT_ObjCMethodExpr) {
+  } else if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&
+             (PreviousNonComment->Type == TT_ObjCMethodExpr ||
+              PreviousNonComment->Type == TT_DictLiteral)) {
     State.Column = ContinuationIndent;
     // FIXME: This is hacky, find a better way. The problem is that in an ObjC
     // method expression, the block should be aligned to the line starting it,
index 5d4c1172c136fda40395d770896655d3012485e4..5bd0822281e3b3145b8b0c7e37401a9b3c3b571b 100644 (file)
@@ -6011,6 +6011,11 @@ TEST_F(FormatTest, ObjCDictLiterals) {
       "  NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : "
       "regularFont,\n"
       "};");
+  verifyFormat(
+      "@{\n"
+      "  NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :\n"
+      "      reeeeeeeeeeeeeeeeeeeeeeeegularFont,\n"
+      "};");
 
   // We should try to be robust in case someone forgets the "@".
   verifyFormat(