Author: benhamilton Date: Thu Apr 12 08:11:51 2018 New Revision: 329917 URL: http://llvm.org/viewvc/llvm-project?rev=329917&view=rev Log: [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 Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestObjC.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=329917&r1=329916&r2=329917&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Apr 12 08:11:51 2018 @@ -2349,9 +2349,12 @@ bool TokenAnnotator::spaceRequiredBetwee : 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)) Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=329917&r1=329916&r2=329917&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Thu Apr 12 08:11:51 2018 @@ -299,13 +299,13 @@ TEST_F(FormatTestObjC, FormatObjCInterfa "+ (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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits