r194241 - clang-format: Properly indent ObjC calls wrapped before first selector

Daniel Jasper djasper at google.com
Thu Nov 7 18:08:01 PST 2013


Author: djasper
Date: Thu Nov  7 20:08:01 2013
New Revision: 194241

URL: http://llvm.org/viewvc/llvm-project?rev=194241&view=rev
Log:
clang-format: Properly indent ObjC calls wrapped before first selector

Before:
  [self // break
      a:a
     aa:aa
  aaaaa:aaa];

After:
  [self // break
          a:a
         aa:aa
      aaaaa:aaa];

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=194241&r1=194240&r2=194241&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Nov  7 20:08:01 2013
@@ -375,7 +375,11 @@ unsigned ContinuationIndenter::addTokenO
                State.Line->StartsDefinition))) {
     State.Column = State.Stack.back().Indent;
   } else if (Current.Type == TT_ObjCSelectorName) {
-    if (State.Stack.back().ColonPos > Current.ColumnWidth) {
+    if (State.Stack.back().ColonPos == 0) {
+      State.Stack.back().ColonPos =
+          State.Stack.back().Indent + Current.LongestObjCSelectorName;
+      State.Column = State.Stack.back().ColonPos - Current.ColumnWidth;
+    } else if (State.Stack.back().ColonPos > Current.ColumnWidth) {
       State.Column = State.Stack.back().ColonPos - Current.ColumnWidth;
     } else {
       State.Column = State.Stack.back().Indent;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194241&r1=194240&r2=194241&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Nov  7 20:08:01 2013
@@ -5474,6 +5474,9 @@ TEST_F(FormatTest, FormatObjCMethodExpr)
       "[self aaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"
       "                    aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n"
       "                    aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];");
+  verifyFormat("[self // break\n"
+               "      a:a\n"
+               "    aaa:aaa];");
 }
 
 TEST_F(FormatTest, ObjCAt) {





More information about the cfe-commits mailing list