[PATCH] D37192: [clang-format] Add support for generic Obj-C categories

2023-09-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Is that really the way we want to recommend formatting that, with the generics 
clause separated from the class name but not separated from the category 
clause?  I'd expect the opposite: write the generics clause with no separation 
after the class name but with separation from the category clause, e.g. 
`NSHashTable (MYFoundation)`.


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D37192/new/

https://reviews.llvm.org/D37192

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


[PATCH] D37192: [clang-format] Add support for generic Obj-C categories

2023-09-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added subscribers: Eugene.Zelenko, rjmccall, shafik.
shafik added a comment.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.

@rjmccall @Eugene.Zelenko this looks like it might still be relevant.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D37192/new/

https://reviews.llvm.org/D37192

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


[PATCH] D37192: [clang-format] Add support for generic Obj-C categories

2017-08-28 Thread Daniel Martín via Phabricator via cfe-commits
danielmartin updated this revision to Diff 112855.
danielmartin added a comment.

Make comment fit in one line


https://reviews.llvm.org/D37192

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -821,6 +821,13 @@
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
 }
+
+TEST_F(FormatTestObjC, FormatGenericObjCCategory) {
+  verifyFormat(
+  "@interface NSHashTable (MYFoundation)\n"
+  "- (void)xyz_addObjectsFromArray:(nonnull NSArray *)array;\n"
+  "@end");
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2096,6 +2096,10 @@
   if (FormatTok->Tok.is(tok::less))
 parseObjCProtocolList();
 
+  // After a protocol list, we can have a category (Obj-C generic category).
+  if (FormatTok->Tok.is(tok::l_paren))
+parseParens();
+
   if (FormatTok->Tok.is(tok::l_brace)) {
 if (Style.BraceWrapping.AfterObjCDeclaration)
   addUnwrappedLine();


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -821,6 +821,13 @@
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
 }
+
+TEST_F(FormatTestObjC, FormatGenericObjCCategory) {
+  verifyFormat(
+  "@interface NSHashTable (MYFoundation)\n"
+  "- (void)xyz_addObjectsFromArray:(nonnull NSArray *)array;\n"
+  "@end");
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2096,6 +2096,10 @@
   if (FormatTok->Tok.is(tok::less))
 parseObjCProtocolList();
 
+  // After a protocol list, we can have a category (Obj-C generic category).
+  if (FormatTok->Tok.is(tok::l_paren))
+parseParens();
+
   if (FormatTok->Tok.is(tok::l_brace)) {
 if (Style.BraceWrapping.AfterObjCDeclaration)
   addUnwrappedLine();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37192: [clang-format] Add support for generic Obj-C categories

2017-08-28 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.




Comment at: lib/Format/UnwrappedLineParser.cpp:2099
 
+  // After a protocol list, we can have a category (Obj-C generic
+  // category).

nit: Seems like this comment would fit on one line.


https://reviews.llvm.org/D37192



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


[PATCH] D37192: [clang-format] Add support for generic Obj-C categories

2017-08-27 Thread Daniel Martín via Phabricator via cfe-commits
danielmartin created this revision.
Herald added a subscriber: klimek.

Objective C supports lightweight generics in categories. This patch
adds support for that in clang-format.


https://reviews.llvm.org/D37192

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -821,6 +821,13 @@
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
 }
+
+TEST_F(FormatTestObjC, FormatGenericObjCCategory) {
+  verifyFormat(
+  "@interface NSHashTable (MYFoundation)\n"
+  "- (void)xyz_addObjectsFromArray:(nonnull NSArray *)array;\n"
+  "@end");
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2096,6 +2096,11 @@
   if (FormatTok->Tok.is(tok::less))
 parseObjCProtocolList();
 
+  // After a protocol list, we can have a category (Obj-C generic
+  // category).
+  if (FormatTok->Tok.is(tok::l_paren))
+parseParens();
+
   if (FormatTok->Tok.is(tok::l_brace)) {
 if (Style.BraceWrapping.AfterObjCDeclaration)
   addUnwrappedLine();


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -821,6 +821,13 @@
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
 }
+
+TEST_F(FormatTestObjC, FormatGenericObjCCategory) {
+  verifyFormat(
+  "@interface NSHashTable (MYFoundation)\n"
+  "- (void)xyz_addObjectsFromArray:(nonnull NSArray *)array;\n"
+  "@end");
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2096,6 +2096,11 @@
   if (FormatTok->Tok.is(tok::less))
 parseObjCProtocolList();
 
+  // After a protocol list, we can have a category (Obj-C generic
+  // category).
+  if (FormatTok->Tok.is(tok::l_paren))
+parseParens();
+
   if (FormatTok->Tok.is(tok::l_brace)) {
 if (Style.BraceWrapping.AfterObjCDeclaration)
   addUnwrappedLine();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits