]> granicus.if.org Git - clang/commitdiff
[clang-format] Don't insert space between ObjC class and lightweight generic
authorBen Hamilton <benhamilton@google.com>
Thu, 12 Apr 2018 15:11:51 +0000 (15:11 +0000)
committerBen Hamilton <benhamilton@google.com>
Thu, 12 Apr 2018 15:11:51 +0000 (15:11 +0000)
Summary:
In D45185, I added clang-format parser support for Objective-C
generics. However, I didn't touch the whitespace logic, so they
got the same space logic as Objective-C protocol lists.

In every example in the Apple SDK and in the documentation,
there is no space between the class name and the opening `<`
for the lightweight generic specification, so this diff
removes the space and updates the tests.

Test Plan: Tests updated. Ran tests with:
  % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D45498

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

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

index 60ebe56d072b65c479091e69faa78d7fef60b258..60244924079e1361cb0733c4932c50f799080b0d 100644 (file)
@@ -2349,9 +2349,12 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
                : 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))
index ded4607334e7d0849c00740841f47deaac403d9e..9c8f252143f085f7dd918bf1b6323fbaa6edf1d6 100644 (file)
@@ -299,13 +299,13 @@ TEST_F(FormatTestObjC, FormatObjCInterface) {
                "+ (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"