r187577 - clang-format: Improve line breaks in @property.

Daniel Jasper djasper at google.com
Thu Aug 1 06:46:58 PDT 2013


Author: djasper
Date: Thu Aug  1 08:46:58 2013
New Revision: 187577

URL: http://llvm.org/viewvc/llvm-project?rev=187577&view=rev
Log:
clang-format: Improve line breaks in @property.

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

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

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=187577&r1=187576&r2=187577&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Aug  1 08:46:58 2013
@@ -1060,7 +1060,7 @@ unsigned TokenAnnotator::splitPenalty(co
   }
 
   // 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(cons
     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))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=187577&r1=187576&r2=187577&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Aug  1 08:46:58 2013
@@ -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) {





More information about the cfe-commits mailing list