Author: benhamilton Date: Tue Apr 3 07:07:09 2018 New Revision: 329069 URL: http://llvm.org/viewvc/llvm-project?rev=329069&view=rev Log: [clang-format/ObjC] Do not insert space after opening brace of ObjC dict literal
Summary: D44816 attempted to fix a few cases where `clang-format` incorrectly inserted a space before the closing brace of an Objective-C dictionary literal. This revealed there were still a few cases where we inserted a space after the opening brace of an Objective-C dictionary literal. This fixes the formatting to be consistent and adds more tests. Test Plan: New tests added. Confirmed tests failed before diff and passed after diff. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Reviewers: djasper, jolesiak, krasimir Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45168 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=329069&r1=329068&r2=329069&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Apr 3 07:07:09 2018 @@ -2480,6 +2480,9 @@ bool TokenAnnotator::spaceRequiredBetwee return false; if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square)) return false; + if (Left.is(tok::l_brace) && Left.endsSequence(TT_DictLiteral, tok::at)) + // Objective-C dictionary literal -> no space after opening brace. + return false; if (Right.is(tok::r_brace) && Right.MatchingParen && Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at)) // Objective-C dictionary literal -> no space before closing brace. Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=329069&r1=329068&r2=329069&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Tue Apr 3 07:07:09 2018 @@ -1021,8 +1021,17 @@ TEST_F(FormatTestObjC, ObjCDictLiterals) " a12345 = @{a12345 : a12345};\n" "}"); verifyFormat("int Foo() {\n" + " a12345 = @{a12345 : @(a12345)};\n" + "}"); + verifyFormat("int Foo() {\n" " a12345 = @{(Foo *)a12345 : @(a12345)};\n" "}"); + verifyFormat("int Foo() {\n" + " a12345 = @{@(a12345) : a12345};\n" + "}"); + verifyFormat("int Foo() {\n" + " a12345 = @{@(a12345) : @YES};\n" + "}"); Style.SpacesInContainerLiterals = false; verifyFormat("int Foo() {\n" " b12345 = @{b12345: b12345};\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits