]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug in ObjC method declaration formatting.
authorDaniel Jasper <djasper@google.com>
Sat, 23 Nov 2013 14:27:27 +0000 (14:27 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 23 Nov 2013 14:27:27 +0000 (14:27 +0000)
Also disallow breaking between "@" and "{" or "[".

Before:
  - (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment
                                               index:(NSUInteger)index
                                          attributes:(NSDictionary *)attributes
                                  nonDigitAttributes:(NSDictionary *)
      nonDigitAttributes;
  [mailComposeViewController
     setToRecipients:@
     [ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]];

After:
  - (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment
                                               index:(NSUInteger)index
                                          attributes:(NSDictionary *)attributes
                                  nonDigitAttributes:
                                      (NSDictionary *)nonDigitAttributes;
  [mailComposeViewController
      setToRecipients:
          @[ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]];

This fixes llvm.org/PR18030.

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

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

index 7c3b8f69de946cad66128e32675066957ee0b45b..53734bcd51101f70332346cb01d7d9a8908fad66 100644 (file)
@@ -1181,7 +1181,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Right.Type == TT_ObjCSelectorName)
     return 0;
   if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
-    return 500;
+    return Line.MightBeFunctionDecl ? 50 : 500;
 
   if (Left.is(tok::l_paren) && InFunctionDecl)
     return 100;
@@ -1416,6 +1416,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
 bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
                                     const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
+  if (Left.is(tok::at))
+    return false;
   if (Right.Type == TT_StartOfName || Right.is(tok::kw_operator))
     return true;
   if (Right.isTrailingComment())
index 5404c49a01719896316bc3af091268c59cb039cd..97444dde8424a608ecb028649e6b0abe00b40b06 100644 (file)
@@ -5751,6 +5751,14 @@ TEST_F(FormatTest, ObjCArrayLiterals) {
                "  @\"aaaaaaaaaaaaaaaaa\",\n"
                "  @\"aaaaaaaaaaaaaaaaa\",\n"
                "];");
+  verifyFormat(
+      "- (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment\n"
+      "                                             index:(NSUInteger)index\n"
+      "                                nonDigitAttributes:\n"
+      "                                    (NSDictionary *)noDigitAttributes;");
+  verifyFormat(
+      "[someFunction someLooooooooooooongParameter:\n"
+      "                  @[ NSBundle.mainBundle.infoDictionary[@\"a\"] ]];");
 }
 
 TEST_F(FormatTest, ReformatRegionAdjustsIndent) {