[clang-format] Always indent wrapped Objective-C selector names
Summary:
Currently, indentation of Objective-C method names which are wrapped
onto the next line due to a long return type is controlled by the
style option `IndentWrappedFunctionNames`.
This diff changes the behavior so we always indent wrapped Objective-C
selector names.
NOTE: I partially reverted https://github.com/llvm-mirror/clang/commit/6159c0fbd1876c7f5f984b4830c664cc78f16e2e / rL242484, as it was causing wrapped selectors to be double-indented. Its tests in FormatTestObjC.cpp still pass.
Test Plan: Tests updated. Ran tests with:
% make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: djasper, jolesiak, stephanemoore, thakis
Reviewed By: djasper
Subscribers: stephanemoore, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D45004
llvm-svn: 329916
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4abf978..d1869d2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7678,16 +7678,18 @@
// When the function name has to be wrapped.
FormatStyle Style = getLLVMStyle();
+ // ObjC ignores IndentWrappedFunctionNames when wrapping methods
+ // and always indents instead.
Style.IndentWrappedFunctionNames = false;
verifyFormat("- (SomeLooooooooooooooooooooongType *)\n"
- "veryLooooooooooongName:(NSString)aaaaaaaaaaaaaa\n"
- " anotherName:(NSString)bbbbbbbbbbbbbb {\n"
+ " veryLooooooooooongName:(NSString)aaaaaaaaaaaaaa\n"
+ " anotherName:(NSString)bbbbbbbbbbbbbb {\n"
"}",
Style);
Style.IndentWrappedFunctionNames = true;
verifyFormat("- (SomeLooooooooooooooooooooongType *)\n"
- " veryLooooooooooongName:(NSString)aaaaaaaaaaaaaa\n"
- " anotherName:(NSString)bbbbbbbbbbbbbb {\n"
+ " veryLooooooooooongName:(NSString)cccccccccccccc\n"
+ " anotherName:(NSString)dddddddddddddd {\n"
"}",
Style);
diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp
index fe86cfe..ded4607 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -536,39 +536,7 @@
" ofSize:(size_t)height\n"
" :(size_t)width;");
Style.ColumnLimit = 40;
- // Make sure selectors with 0, 1, or more arguments are not indented
- // when IndentWrappedFunctionNames is false.
- Style.IndentWrappedFunctionNames = false;
- verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n");
- verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a;\n");
- verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a;\n");
- verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a;\n");
- verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a;\n");
-
- // Continuation indent width should win over aligning colons if the function
- // name is long.
- Style = getGoogleStyle(FormatStyle::LK_ObjC);
- Style.ColumnLimit = 40;
- Style.IndentWrappedFunctionNames = true;
- verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
- " dontAlignNamef:(NSRect)theRect {\n"
- "}");
-
- // Make sure we don't break aligning for short parameter names.
- verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
- " aShortf:(NSRect)theRect {\n"
- "}");
-
- // Make sure selectors with 0, 1, or more arguments are indented
- // when IndentWrappedFunctionNames is true.
+ // Make sure selectors with 0, 1, or more arguments are indented when wrapped.
verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n");
verifyFormat("- (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
@@ -583,6 +551,19 @@
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa:(int)a;\n");
+ // Continuation indent width should win over aligning colons if the function
+ // name is long.
+ Style = getGoogleStyle(FormatStyle::LK_ObjC);
+ Style.ColumnLimit = 40;
+ verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
+ " dontAlignNamef:(NSRect)theRect {\n"
+ "}");
+
+ // Make sure we don't break aligning for short parameter names.
+ verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
+ " aShortf:(NSRect)theRect {\n"
+ "}");
+
// Format pairs correctly.
Style.ColumnLimit = 80;
verifyFormat("- (void)drawRectOn:(id)surface\n"