]> granicus.if.org Git - clang/commitdiff
clang-format: Improve linebreaking and indentation for ObjC calls.
authorDaniel Jasper <djasper@google.com>
Fri, 8 Nov 2013 17:33:24 +0000 (17:33 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 Nov 2013 17:33:24 +0000 (17:33 +0000)
Before:
  popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
      iniithContentRect:
          NSMakRet(origin_global.x, origin_global.y, pos.width(), pos.height())
                syeMask:NSBorderlessWindowMask
                  bking:NSBackingStoreBuffered
                    der:NO]);
  [self param:function( //
      parameter)]

After:
  popup_wdow_.reset([[RenderWidgetPopupWindow alloc]
      iniithContentRect:NSMakRet(origin_global.x, origin_global.y, pos.width(),
                                 pos.height())
                syeMask:NSBorderlessWindowMask
                  bking:NSBackingStoreBuffered
                    der:NO]);
  [self param:function( //
                  parameter)]

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

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

index d075c7482d06b6f44ca903ba8ec2d935e427dac3..63232beb9f0fe57b562bd10658860875a49e4a6d 100644 (file)
@@ -277,7 +277,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
     // Treat the condition inside an if as if it was a second function
     // parameter, i.e. let nested calls have a continuation indent.
     State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(".
-  else if (Previous.is(tok::comma))
+  else if (Previous.is(tok::comma) || Previous.Type == TT_ObjCMethodExpr)
     State.Stack.back().LastSpace = State.Column;
   else if ((Previous.Type == TT_BinaryOperator ||
             Previous.Type == TT_ConditionalExpr ||
index 474f6a5adbb948a069ed1cfdc8fbc984bfed20ec..074e1d78454b82ff49bdd0ae0f64d8d124ff2728 100644 (file)
@@ -1180,7 +1180,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Right.Type == TT_ObjCSelectorName)
     return 0;
   if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
-    return 20;
+    return 50;
 
   if (Left.is(tok::l_paren) && InFunctionDecl)
     return 100;
index 776bf49a4aa8764e97c91d128c405c2ecea84f85..7e4131bd686296071ea7924e4c637ca2e1be7476 100644 (file)
@@ -5432,6 +5432,16 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
       "                  backing:NSBackingStoreBuffered\n"
       "                    defer:NO]);\n"
       "}");
+  verifyFormat(
+      "void f() {\n"
+      "  popup_wdow_.reset([[RenderWidgetPopupWindow alloc]\n"
+      "      iniithContentRect:NSMakRet(origin_global.x, origin_global.y,\n"
+      "                                 pos.width(), pos.height())\n"
+      "                syeMask:NSBorderlessWindowMask\n"
+      "                  bking:NSBackingStoreBuffered\n"
+      "                    der:NO]);\n"
+      "}",
+      getLLVMStyleWithColumns(70));
   verifyFormat("[contentsContainer replaceSubview:[subviews objectAtIndex:0]\n"
                "                             with:contentsNativeView];");
 
@@ -5462,6 +5472,8 @@ TEST_F(FormatTest, FormatObjCMethodExpr) {
                "    aaaaaaaaaa:bbbbbbbbbbbbbbbbb\n"
                "         aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n"
                "          aaaa:bbb];");
+  verifyFormat("[self param:function( //\n"
+               "                parameter)]");
   verifyFormat(
       "[self aaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"
       "                 aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa |\n"