r219564 - clang-format: [ObjC] Wrap ObjC method declarations before annotations.
Daniel Jasper
djasper at google.com
Sat Oct 11 01:24:57 PDT 2014
Author: djasper
Date: Sat Oct 11 03:24:56 2014
New Revision: 219564
URL: http://llvm.org/viewvc/llvm-project?rev=219564&view=rev
Log:
clang-format: [ObjC] Wrap ObjC method declarations before annotations.
Before:
- (instancetype)initXxxxxxxxxxxxxxxxxxxxxxxxx:(id<x>)x
y:(id<yyyyyyyyyyyyyyyyyyyy>)
y NS_DESIGNATED_INITIALIZER;
After:
- (instancetype)initXxxxxxxxxxxxxxxxxxxxxxxxx:(id<x>)x
y:(id<yyyyyyyyyyyyyyyyyyyy>)y
NS_DESIGNATED_INITIALIZER;
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=219564&r1=219563&r2=219564&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Oct 11 03:24:56 2014
@@ -1432,6 +1432,11 @@ unsigned TokenAnnotator::splitPenalty(co
if (Right.Type == TT_TrailingAnnotation &&
(!Right.Next || Right.Next->isNot(tok::l_paren))) {
+ // Moving trailing annotations to the next line is fine for ObjC method
+ // declarations.
+ if (Line.First->Type == TT_ObjCMethodSpecifier)
+
+ return 10;
// Generally, breaking before a trailing annotation is bad unless it is
// function-like. It seems to be especially preferable to keep standard
// annotations (i.e. "const", "final" and "override") on the same line.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=219564&r1=219563&r2=219564&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Oct 11 03:24:56 2014
@@ -6452,6 +6452,10 @@ TEST_F(FormatTest, FormatObjCMethodDecla
" evenLongerKeyword:(float)theInterval\n"
" error:(NSError **)theError {\n"
"}");
+ verifyFormat("- (instancetype)initXxxxxx:(id<x>)x\n"
+ " y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n"
+ " NS_DESIGNATED_INITIALIZER;",
+ getLLVMStyleWithColumns(60));
}
TEST_F(FormatTest, FormatObjCMethodExpr) {
More information about the cfe-commits
mailing list