From c5d09e5e3e3cf3e75cdc185db5ed6fa360cc2bc1 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 7 May 2015 14:19:59 +0000 Subject: [PATCH] clang-format: Improve r236597, Properly indent method calls without inputs. Before: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236730 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 8 ++++++-- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 430fe77239..ee06bc6cb5 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -584,9 +584,13 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return State.Stack.back().StartOfArraySubscripts; return ContinuationIndent; } - if (NextNonComment->is(TT_StartOfName) && NextNonComment->Next && - NextNonComment->Next->is(TT_ObjCMethodExpr)) + + // This ensure that we correctly format ObjC methods calls without inputs, + // i.e. where the last element isn't selector like: [callee method]; + if (NextNonComment->is(tok::identifier) && NextNonComment->FakeRParens == 0 && + NextNonComment->Next && NextNonComment->Next->is(TT_ObjCMethodExpr)) return State.Stack.back().Indent; + if (NextNonComment->isOneOf(TT_StartOfName, TT_PointerOrReference) || Previous.isOneOf(tok::coloncolon, tok::equal)) return ContinuationIndent; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 9f034eca37..1079bef41e 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -49,7 +49,7 @@ private: ScopedContextCreator ContextCreator(*this, tok::less, 10); // If this angle is in the context of an expression, we need to be more - // hesitant to detect it as opening template parameters. + // hesitant to detect it as opening template parameters. bool InExprContext = Contexts.back().IsExpression; Contexts.back().IsExpression = false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 4e33aa9da5..0995bb162a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7186,6 +7186,8 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { " hints:nil];"); verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];"); + verifyFormat("[aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];"); verifyFormat( "scoped_nsobject message(\n" -- 2.40.0