[PATCH] D45004: [clang-format] Always indent wrapped Objective-C selector names

2018-04-12 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329916: [clang-format] Always indent wrapped Objective-C 
selector names (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45004?vs=142183&id=142187#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestObjC.cpp

Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -26,6 +26,13 @@
 namespace clang {
 namespace format {
 
+// Returns true if a TT_SelectorName should be indented when wrapped,
+// false otherwise.
+static bool shouldIndentWrappedSelectorName(const FormatStyle &Style,
+LineType LineType) {
+  return Style.IndentWrappedFunctionNames || LineType == LT_ObjCMethodDecl;
+}
+
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const FormatToken &Tok) {
@@ -698,7 +705,7 @@
 State.Stack.back().AlignColons = false;
   } else {
 State.Stack.back().ColonPos =
-(Style.IndentWrappedFunctionNames
+(shouldIndentWrappedSelectorName(Style, State.Line->Type)
  ? std::max(State.Stack.back().Indent,
 State.FirstIndent + Style.ContinuationIndentWidth)
  : State.Stack.back().Indent) +
@@ -897,7 +904,7 @@
   if (NextNonComment->is(TT_SelectorName)) {
 if (!State.Stack.back().ObjCSelectorNameFound) {
   unsigned MinIndent = State.Stack.back().Indent;
-  if (Style.IndentWrappedFunctionNames)
+  if (shouldIndentWrappedSelectorName(Style, State.Line->Type))
 MinIndent = std::max(MinIndent,
  State.FirstIndent + Style.ContinuationIndentWidth);
   // If LongestObjCSelectorName is 0, we are indenting the first
@@ -1000,13 +1007,8 @@
   if (Current.isMemberAccess())
 State.Stack.back().StartOfFunctionCall =
 !Current.NextOperator ? 0 : State.Column;
-  if (Current.is(TT_SelectorName)) {
+  if (Current.is(TT_SelectorName))
 State.Stack.back().ObjCSelectorNameFound = true;
-if (Style.IndentWrappedFunctionNames) {
-  State.Stack.back().Indent =
-  State.FirstIndent + Style.ContinuationIndentWidth;
-}
-  }
   if (Current.is(TT_CtorInitializerColon) &&
   Style.BreakConstructorInitializers != FormatStyle::BCIS_AfterColon) {
 // Indent 2 from the column, so:
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7678,16 +7678,18 @@
 
   // When the function name has to be wrapped.
   FormatStyle Style = getLLVMStyle();
+  // ObjC ignores IndentWrappedFunctionNames when wrapping methods
+  // and always indents instead.
   Style.IndentWrappedFunctionNames = false;
   verifyFormat("- (SomeLongType *)\n"
-   "veryLooongName:(NSString)aa\n"
-   "   anotherName:(NSString)bb {\n"
+   "veryLooongName:(NSString)aa\n"
+   "   anotherName:(NSString)bb {\n"
"}",
Style);
   Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (SomeLongType *)\n"
-   "veryLooongName:(NSString)aa\n"
-   "   anotherName:(NSString)bb {\n"
+   "veryLooongName:(NSString)cc\n"
+   "   anotherName:(NSString)dd {\n"
"}",
Style);
 
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -536,28 +536,25 @@
"ofSize:(size_t)height\n"
"  :(size_t)width;");
   Style.ColumnLimit = 40;
-  // Make sure selectors with 0, 1, or more arguments are not indented
-  // when IndentWrappedFunctionNames is false.
-  Style.IndentWrappedFunctionNames = false;
+  // Make sure selectors with 0, 1, or more arguments are indented when wrapped.
   verifyFormat("- (a)\n"
-   ";\n");
+   ";\n");
   verifyFormat("- (a)\n"
-   ":(int)a;\n");
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   "aa

[PATCH] D45004: [clang-format] Always indent wrapped Objective-C selector names

2018-04-12 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added inline comments.



Comment at: unittests/Format/FormatTest.cpp:7666
   FormatStyle Style = getLLVMStyle();
+  // ObjC ignores IndentWrappedFunctionNames when wrapping methods.
   Style.IndentWrappedFunctionNames = false;

djasper wrote:
> maybe: .. and always indents. ?
Sure, done.


Repository:
  rC Clang

https://reviews.llvm.org/D45004



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45004: [clang-format] Always indent wrapped Objective-C selector names

2018-04-12 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 142183.
benhamilton marked an inline comment as done.
benhamilton added a comment.

Update comment.


Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -536,28 +536,25 @@
"ofSize:(size_t)height\n"
"  :(size_t)width;");
   Style.ColumnLimit = 40;
-  // Make sure selectors with 0, 1, or more arguments are not indented
-  // when IndentWrappedFunctionNames is false.
-  Style.IndentWrappedFunctionNames = false;
+  // Make sure selectors with 0, 1, or more arguments are indented when wrapped.
   verifyFormat("- (a)\n"
-   ";\n");
+   ";\n");
   verifyFormat("- (a)\n"
-   ":(int)a;\n");
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   ":(int)a\n"
-   ":(int)a;\n");
+   ":(int)a\n"
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   " aaa:(int)a\n"
-   ":(int)a;\n");
+   " aaa:(int)a\n"
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   ":(int)a\n"
-   " aaa:(int)a;\n");
+   ":(int)a\n"
+   " aaa:(int)a;\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
-  Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
"dontAlignNamef:(NSRect)theRect {\n"
"}");
@@ -567,22 +564,6 @@
"   aShortf:(NSRect)theRect {\n"
"}");
 
-  // Make sure selectors with 0, 1, or more arguments are indented
-  // when IndentWrappedFunctionNames is true.
-  verifyFormat("- (a)\n"
-   ";\n");
-  verifyFormat("- (a)\n"
-   ":(int)a;\n");
-  verifyFormat("- (a)\n"
-   ":(int)a\n"
-   ":(int)a;\n");
-  verifyFormat("- (a)\n"
-   " aaa:(int)a\n"
-   ":(int)a;\n");
-  verifyFormat("- (a)\n"
-   ":(int)a\n"
-   " aaa:(int)a;\n");
-
   // Format pairs correctly.
   Style.ColumnLimit = 80;
   verifyFormat("- (void)drawRectOn:(id)surface\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7663,16 +7663,18 @@
 
   // When the function name has to be wrapped.
   FormatStyle Style = getLLVMStyle();
+  // ObjC ignores IndentWrappedFunctionNames when wrapping methods
+  // and always indents instead.
   Style.IndentWrappedFunctionNames = false;
   verifyFormat("- (SomeLongType *)\n"
-   "veryLooongName:(NSString)aa\n"
-   "   anotherName:(NSString)bb {\n"
+   "veryLooongName:(NSString)aa\n"
+   "   anotherName:(NSString)bb {\n"
"}",
Style);
   Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (SomeLongType *)\n"
-   "veryLooongName:(NSString)aa\n"
-   "   anotherName:(NSString)bb {\n"
+   "veryLooongName:(NSString)cc\n"
+   "   anotherName:(NSString)dd {\n"
"}",
Style);
 
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/Co

[PATCH] D45004: [clang-format] Always indent wrapped Objective-C selector names

2018-04-12 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added inline comments.
This revision is now accepted and ready to land.



Comment at: unittests/Format/FormatTest.cpp:7666
   FormatStyle Style = getLLVMStyle();
+  // ObjC ignores IndentWrappedFunctionNames when wrapping methods.
   Style.IndentWrappedFunctionNames = false;

maybe: .. and always indents. ?


Repository:
  rC Clang

https://reviews.llvm.org/D45004



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45004: [clang-format] Always indent wrapped Objective-C selector names

2018-04-10 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

> Ok, you know the ObjC community much better than I do. If you think that 
> adding the indentation for ObjC irrespective of the option works for most 
> people, I am happy to go with it.

OK, I went ahead and implemented unconditional indenting of wrapped ObjC 
selectors and removed the configuration setting.

I had to partially revert r242484; with it, we were getting 8-column indenting, 
and without it, its tests still pass, so I suspect it's no longer necessary.


Repository:
  rC Clang

https://reviews.llvm.org/D45004



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45004: [clang-format] Always indent wrapped Objective-C selector names

2018-04-10 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 141872.
benhamilton added a comment.

- Unconditionally indent wrapped ObjC selector names.
- Partially revert r242484, as it was causing double-indenting (the tests still 
pass with it reverted, so I suspect it's no longer necessary).


Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -536,28 +536,25 @@
"ofSize:(size_t)height\n"
"  :(size_t)width;");
   Style.ColumnLimit = 40;
-  // Make sure selectors with 0, 1, or more arguments are not indented
-  // when IndentWrappedFunctionNames is false.
-  Style.IndentWrappedFunctionNames = false;
+  // Make sure selectors with 0, 1, or more arguments are indented when wrapped.
   verifyFormat("- (a)\n"
-   ";\n");
+   ";\n");
   verifyFormat("- (a)\n"
-   ":(int)a;\n");
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   ":(int)a\n"
-   ":(int)a;\n");
+   ":(int)a\n"
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   " aaa:(int)a\n"
-   ":(int)a;\n");
+   " aaa:(int)a\n"
+   ":(int)a;\n");
   verifyFormat("- (a)\n"
-   ":(int)a\n"
-   " aaa:(int)a;\n");
+   ":(int)a\n"
+   " aaa:(int)a;\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
-  Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
"dontAlignNamef:(NSRect)theRect {\n"
"}");
@@ -567,22 +564,6 @@
"   aShortf:(NSRect)theRect {\n"
"}");
 
-  // Make sure selectors with 0, 1, or more arguments are indented
-  // when IndentWrappedFunctionNames is true.
-  verifyFormat("- (a)\n"
-   ";\n");
-  verifyFormat("- (a)\n"
-   ":(int)a;\n");
-  verifyFormat("- (a)\n"
-   ":(int)a\n"
-   ":(int)a;\n");
-  verifyFormat("- (a)\n"
-   " aaa:(int)a\n"
-   ":(int)a;\n");
-  verifyFormat("- (a)\n"
-   ":(int)a\n"
-   " aaa:(int)a;\n");
-
   // Format pairs correctly.
   Style.ColumnLimit = 80;
   verifyFormat("- (void)drawRectOn:(id)surface\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7663,16 +7663,17 @@
 
   // When the function name has to be wrapped.
   FormatStyle Style = getLLVMStyle();
+  // ObjC ignores IndentWrappedFunctionNames when wrapping methods.
   Style.IndentWrappedFunctionNames = false;
   verifyFormat("- (SomeLongType *)\n"
-   "veryLooongName:(NSString)aa\n"
-   "   anotherName:(NSString)bb {\n"
+   "veryLooongName:(NSString)aa\n"
+   "   anotherName:(NSString)bb {\n"
"}",
Style);
   Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (SomeLongType *)\n"
-   "veryLooongName:(NSString)aa\n"
-   "   anotherName:(NSString)bb {\n"
+   "veryLooongName:(NSString)cc\n"
+   "   anotherName:(NSString)dd {\n"
"}",
Style);
 
Index: lib/Format/ContinuationIndenter.cpp
==