From df72e9851a33d137de1d323c06feea3faf16deb3 Mon Sep 17 00:00:00 2001 From: Ben Hamilton Date: Thu, 12 Apr 2018 15:11:51 +0000 Subject: [clang-format] Don't insert space between ObjC class and lightweight generic 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 llvm-svn: 329917 --- clang/lib/Format/TokenAnnotator.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'clang/lib/Format') diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 60ebe56d072..60244924079 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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)) -- cgit v1.2.3