r320714 - [ClangFormat] IndentWrappedFunctionNames should be true in the google ObjC style
Ben Hamilton via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 14 08:17:38 PST 2017
Author: benhamilton
Date: Thu Dec 14 08:17:38 2017
New Revision: 320714
URL: http://llvm.org/viewvc/llvm-project?rev=320714&view=rev
Log:
[ClangFormat] IndentWrappedFunctionNames should be true in the google ObjC style
Summary:
If we write the following code, it goes over 100 columns, so we need to wrap it:
```
- (VeryLongReturnTypeName)veryLongMethodParameter:(VeryLongParameterName)thisIsAVeryLongParameterName
longMethodParameter:(LongParameterName)thisIsAlsoAnotherLongParameterName;
```
Currently, clang-format with the google style aligns the method parameter names on the first column:
```
- (VeryLongReturnTypeName)
veryLongMethodParameter:(VeryLongParameterName)thisIsAVeryLongParameterName
longMethodParameter:(LongParameterName)thisIsAlsoAnotherLongParameterName;
```
We'd like clang-format in the google style to align these to column 4 for Objective-C:
```
- (VeryLongReturnTypeName)
veryLongMethodParameter:(VeryLongParameterName)thisIsAVeryLongParameterName
longMethodParameter:(LongParameterName)thisIsAlsoAnotherLongParameterName;
```
Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: krasimir, djasper, klimek
Reviewed By: djasper
Subscribers: cfe-commits, thakis
Differential Revision: https://reviews.llvm.org/D41195
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=320714&r1=320713&r2=320714&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Dec 14 08:17:38 2017
@@ -732,6 +732,7 @@ FormatStyle getGoogleStyle(FormatStyle::
GoogleStyle.SpacesInContainerLiterals = false;
} else if (Language == FormatStyle::LK_ObjC) {
GoogleStyle.ColumnLimit = 100;
+ GoogleStyle.IndentWrappedFunctionNames = true;
}
return GoogleStyle;
Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=320714&r1=320713&r2=320714&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Thu Dec 14 08:17:38 2017
@@ -382,9 +382,9 @@ TEST_F(FormatTestObjC, FormatObjCMethodD
" ofSize:(size_t)height\n"
" :(size_t)width;");
+ Style = getGoogleStyle(FormatStyle::LK_ObjC);
// 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"
@@ -395,7 +395,10 @@ TEST_F(FormatTestObjC, FormatObjCMethodD
verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
" aShortf:(NSRect)theRect {\n"
"}");
-
+ // Wrapped method parameters should be indented.
+ verifyFormat("- (LongReturnTypeName)\n"
+ " longParam:(ParamName)longParamName\n"
+ " param:(paramName)paramName;");
// Format pairs correctly.
Style.ColumnLimit = 80;
verifyFormat("- (void)drawRectOn:(id)surface\n"
More information about the cfe-commits
mailing list