From: Daniel Jasper Date: Thu, 1 Aug 2013 13:46:58 +0000 (+0000) Subject: clang-format: Improve line breaks in @property. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa9e7b18a88d715b63e7b65d1b26a1759decc177;p=clang clang-format: Improve line breaks in @property. Before: @property(nonatomic, assign, readonly) NSString *looooooooooooooooooooooooooooongName; After: @property(nonatomic, assign, readonly) NSString *looooooooooooooooooooooooooooongName; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187577 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b9d26ca521..e0e24e2748 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1060,7 +1060,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, } // Breaking before a trailing 'const' or not-function-like annotation is bad. - if (Left.is(tok::r_paren) && + if (Left.is(tok::r_paren) && Line.Type != LT_ObjCProperty && (Right.is(tok::kw_const) || (Right.is(tok::identifier) && Right.Next && Right.Next->isNot(tok::l_paren)))) return 150; @@ -1253,6 +1253,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return true; if (Right.Type == TT_ObjCSelectorName) return true; + if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty) + return true; if (Left.ClosesTemplateDeclaration) return true; if (Right.Type == TT_ConditionalExpr || Right.is(tok::question)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d5b9f27699..6a5f0228fc 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4663,6 +4663,11 @@ TEST_F(FormatTest, FormatObjCProtocol) { "@optional\n" "@property(assign) int madProp;\n" "@end\n"); + + verifyFormat("@property(nonatomic, assign, readonly)\n" + " int *looooooooooooooooooooooooooooongNumber;\n" + "@property(nonatomic, assign, readonly)\n" + " NSString *looooooooooooooooooooooooooooongName;"); } TEST_F(FormatTest, FormatObjCMethodDeclarations) {