]> granicus.if.org Git - clang/commitdiff
clang-format: [ObjC] Wrap ObjC method declarations before annotations.
authorDaniel Jasper <djasper@google.com>
Sat, 11 Oct 2014 08:24:56 +0000 (08:24 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 11 Oct 2014 08:24:56 +0000 (08:24 +0000)
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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219564 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 4a964ed41d8458590ad74ba44498eba3db069eb1..1f8ac5ee10743e583ff2f55e1ec007603cbf1d72 100644 (file)
@@ -1432,6 +1432,11 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
 
   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.
index 4091cd5c10f3e7aaae223e40fb8acba3485f269a..758e5042262a706f5bfdf7f98883a2b66d95d7b4 100644 (file)
@@ -6452,6 +6452,10 @@ TEST_F(FormatTest, FormatObjCMethodDeclarations) {
                "    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) {