]> granicus.if.org Git - clang/commitdiff
clang-format: Fix ObjC literal indentation in Google style.
authorDaniel Jasper <djasper@google.com>
Tue, 22 Oct 2013 15:45:58 +0000 (15:45 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 22 Oct 2013 15:45:58 +0000 (15:45 +0000)
Style guide demands a two-space indent.

Before:
  NSArray *arguments = @[
      kind == kUserTicket ? @"--user-store" : @"--system-store",
      @"--print-tickets",
      @"--productid",
      @"com.google.Chrome"
  ];

After:
  NSArray *arguments = @[
    kind == kUserTicket ? @"--user-store" : @"--system-store",
    @"--print-tickets",
    @"--productid",
    @"com.google.Chrome"
  ];

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

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

index 18f0c33452d65109a7d0596d2f8386edb9effc7b..16b1147fd58c0ca89c3bedc45338272ad42d4e5e 100644 (file)
@@ -562,11 +562,11 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
         BreakBeforeParameter = true;
       } else {
         NewIndent = State.Stack.back().LastSpace;
-        if (Style.Cpp11BracedListStyle)
-          NewIndent += Style.ContinuationIndentWidth;
-        else {
+        if (Current.opensBlockTypeList(Style)) {
           NewIndent += Style.IndentWidth;
           ++NewIndentLevel;
+        } else {
+          NewIndent += Style.ContinuationIndentWidth;
         }
       }
       const FormatToken *NextNoComment = Current.getNextNonComment();
index 52cc3ce530dc79b13b50ea3452f487df9251e2c6..2001d427a69b02ffb01dbad0f65407e170c433e3 100644 (file)
@@ -339,15 +339,18 @@ struct FormatToken {
     return Tok;
   }
 
+  /// \brief Returns \c true if this tokens starts a block-type list, i.e. a
+  /// list that should be indented with a block indent.
+  bool opensBlockTypeList(const FormatStyle &Style) const {
+    return Type == TT_ArrayInitializerLSquare ||
+           (is(tok::l_brace) &&
+            (BlockKind == BK_Block || Type == TT_ObjCDictLiteral ||
+             !Style.Cpp11BracedListStyle));
+  }
+
+  /// \brief Same as opensBlockTypeList, but for the closing token.
   bool closesBlockTypeList(const FormatStyle &Style) const {
-    if (is(tok::r_brace) && MatchingParen &&
-        (MatchingParen->BlockKind == BK_Block ||
-         !Style.Cpp11BracedListStyle))
-      return true;
-    if (is(tok::r_square) && MatchingParen &&
-        MatchingParen->Type == TT_ArrayInitializerLSquare)
-      return true;
-    return false;
+    return MatchingParen && MatchingParen->opensBlockTypeList(Style);
   }
 
   FormatToken *MatchingParen;
index 6dd94133922a592ffca258b125694131e132d2d5..d8ff2fcecaac16e0c47cef9a8451806e733b3805 100644 (file)
@@ -5416,6 +5416,18 @@ TEST_F(FormatTest, ObjCLiterals) {
       "  @\"--productid\",\n"
       "  @\"com.google.Chrome\"\n"
       "];");
+  verifyGoogleFormat(
+      "@{\n"
+      "  NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : "
+      "regularFont,\n"
+      "};");
+  verifyGoogleFormat(
+      "NSArray *arguments = @[\n"
+      "  kind == kUserTicket ? @\"--user-store\" : @\"--system-store\",\n"
+      "  @\"--print-tickets\",\n"
+      "  @\"--productid\",\n"
+      "  @\"com.google.Chrome\"\n"
+      "];");
 }
 
 TEST_F(FormatTest, ReformatRegionAdjustsIndent) {