kmensah updated this revision to Diff 30257.
kmensah added a comment.

Fixing per djasper's comments.


Repository:
  rL LLVM

http://reviews.llvm.org/D11300

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

Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7323,6 +7323,14 @@
                "    aaa:aaa];");
   verifyFormat("bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa ||\n"
                "          [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa);");
+
+  // Allow PenaltyBreakBeforeFirstCallParameter to stop us from breaking before
+  // the first selector name.
+  FormatStyle selectorBreakStyle = getGoogleStyleWithColumns(60);
+  selectorBreakStyle.PenaltyBreakBeforeFirstCallParameter = 10000;
+  verifyFormat("[self function1:[OtherType function2:longParamaterName1\n"
+               "                               param:longParameterName2]];",
+               selectorBreakStyle);
 }
 
 TEST_F(FormatTest, ObjCAt) {
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1745,8 +1745,14 @@
 
   // In Objective-C method expressions, prefer breaking before "param:" over
   // breaking after it.
-  if (Right.is(TT_SelectorName))
+  if (Right.is(TT_SelectorName)) {
+    // While we prefer breaking before param, if this is the first paramater
+    // apply PenaltyBreakBeforeFirstCallParameter
+    if (Right.LongestObjCSelectorName != 0) {
+      return Style.PenaltyBreakBeforeFirstCallParameter;
+    }
     return 0;
+  }
   if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))
     return Line.MightBeFunctionDecl ? 50 : 500;
 


Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7323,6 +7323,14 @@
                "    aaa:aaa];");
   verifyFormat("bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa ||\n"
                "          [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa);");
+
+  // Allow PenaltyBreakBeforeFirstCallParameter to stop us from breaking before
+  // the first selector name.
+  FormatStyle selectorBreakStyle = getGoogleStyleWithColumns(60);
+  selectorBreakStyle.PenaltyBreakBeforeFirstCallParameter = 10000;
+  verifyFormat("[self function1:[OtherType function2:longParamaterName1\n"
+               "                               param:longParameterName2]];",
+               selectorBreakStyle);
 }
 
 TEST_F(FormatTest, ObjCAt) {
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1745,8 +1745,14 @@
 
   // In Objective-C method expressions, prefer breaking before "param:" over
   // breaking after it.
-  if (Right.is(TT_SelectorName))
+  if (Right.is(TT_SelectorName)) {
+    // While we prefer breaking before param, if this is the first paramater
+    // apply PenaltyBreakBeforeFirstCallParameter
+    if (Right.LongestObjCSelectorName != 0) {
+      return Style.PenaltyBreakBeforeFirstCallParameter;
+    }
     return 0;
+  }
   if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))
     return Line.MightBeFunctionDecl ? 50 : 500;
 
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to