[PATCH] D45498: [clang-format] Don't insert space between ObjC class and lightweight generic

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 12 08:07:54 PDT 2018


benhamilton updated this revision to Diff 142186.
benhamilton marked an inline comment as done.
benhamilton added a comment.

Avoid else after return. Clean up logic so it doesn't need a comment.


Repository:
  rC Clang

https://reviews.llvm.org/D45498

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


Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -299,13 +299,13 @@
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo <Baz : Blech> : Bar <Baz, Quux> {\n"
+  verifyFormat("@interface Foo<Baz : Blech> : Bar <Baz, Quux> {\n"
                "  int _i;\n"
                "}\n"
                "+ (id)init;\n"
                "@end");
 
-  verifyFormat("@interface Foo <Bar : Baz <Blech>> : Xyzzy <Corge> {\n"
+  verifyFormat("@interface Foo<Bar : Baz <Blech>> : Xyzzy <Corge> {\n"
                "  int _i;\n"
                "}\n"
                "+ (id)init;\n"
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2349,9 +2349,12 @@
                : Style.SpacesInParentheses;
   if (Right.isOneOf(tok::semi, tok::comma))
     return false;
-  if (Right.is(tok::less) && Line.Type == LT_ObjCDecl &&
-      Style.ObjCSpaceBeforeProtocolList)
-    return true;
+  if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) {
+    bool IsLightweightGeneric =
+        Right.MatchingParen && Right.MatchingParen->Next &&
+        Right.MatchingParen->Next->is(tok::colon);
+    return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList;
+  }
   if (Right.is(tok::less) && Left.is(tok::kw_template))
     return Style.SpaceAfterTemplateKeyword;
   if (Left.isOneOf(tok::exclaim, tok::tilde))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45498.142186.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180412/87970c2e/attachment.bin>


More information about the cfe-commits mailing list