clang-format: Improve line breaks in @property.

Before:
  @property(nonatomic, assign,
            readonly) NSString *looooooooooooooooooooooooooooongName;

After:
  @property(nonatomic, assign, readonly)
      NSString *looooooooooooooooooooooooooooongName;

llvm-svn: 187577
This commit is contained in:
Daniel Jasper 2013-08-01 13:46:58 +00:00
parent b1266b5447
commit 9688ff197e
2 changed files with 8 additions and 1 deletions

View File

@ -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))

View File

@ -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) {