]> granicus.if.org Git - clang/commitdiff
[clang-format/ObjC] Do not insert space after opening brace of ObjC dict literal
authorBen Hamilton <benhamilton@google.com>
Tue, 3 Apr 2018 14:07:09 +0000 (14:07 +0000)
committerBen Hamilton <benhamilton@google.com>
Tue, 3 Apr 2018 14:07:09 +0000 (14:07 +0000)
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

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

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

index 24494b69826c7aa68f74f326816deff56f2161b3..038121e8ef8335f883e3899fe601fa44d738a683 100644 (file)
@@ -2480,6 +2480,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     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.
index 5c12911be123589b1fe8d03bc51e69722d898d48..ed5d1aa25609b50e3d39eb61e15e373cbacd630f 100644 (file)
@@ -1020,9 +1020,18 @@ TEST_F(FormatTestObjC, ObjCDictLiterals) {
   verifyFormat("int Foo() {\n"
                "  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"