From: Daniel Jasper Date: Fri, 8 Nov 2013 17:33:24 +0000 (+0000) Subject: clang-format: Improve linebreaking and indentation for ObjC calls. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=deb61c5169531895a3cfa02d77b4d8f315f5e64b;p=clang clang-format: Improve linebreaking and indentation for ObjC calls. 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 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index d075c7482d..63232beb9f 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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 || diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 474f6a5adb..074e1d7845 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 776bf49a4a..7e4131bd68 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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"