summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-07 14:19:59 +0000
committerDaniel Jasper <djasper@google.com>2015-05-07 14:19:59 +0000
commit9c95013e8fd3aeccad4d9ab2bab208ed532f05ec (patch)
tree8e8b1e7f3d7f7cd309f91f9d079620e886b4db36
parent1a3bd31e52234d332a3282e7fc2119d3a6527ac6 (diff)
downloadbcm5719-llvm-9c95013e8fd3aeccad4d9ab2bab208ed532f05ec.tar.gz
bcm5719-llvm-9c95013e8fd3aeccad4d9ab2bab208ed532f05ec.zip
clang-format: Improve r236597, Properly indent method calls without inputs.
Before: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; llvm-svn: 236730
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp8
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp2
3 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 430fe772392..ee06bc6cb5b 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/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/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 9f034eca379..1079bef41e3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4e33aa9da55..0995bb162a0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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<NSTextField> message(\n"
OpenPOWER on IntegriCloud