diff options
| author | Daniel Jasper <djasper@google.com> | 2013-10-22 15:45:58 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-10-22 15:45:58 +0000 |
| commit | b8f61682182ed8b8a641761d9948506eac397796 (patch) | |
| tree | 7807ded6d1b8c988e9da48d5f9a62d1d4f0c53d9 | |
| parent | 1db6c3868760d6c9c05b238b636f155d3247ecc2 (diff) | |
| download | bcm5719-llvm-b8f61682182ed8b8a641761d9948506eac397796.tar.gz bcm5719-llvm-b8f61682182ed8b8a641761d9948506eac397796.zip | |
clang-format: Fix ObjC literal indentation in Google style.
Style guide demands a two-space indent.
Before:
NSArray *arguments = @[
kind == kUserTicket ? @"--user-store" : @"--system-store",
@"--print-tickets",
@"--productid",
@"com.google.Chrome"
];
After:
NSArray *arguments = @[
kind == kUserTicket ? @"--user-store" : @"--system-store",
@"--print-tickets",
@"--productid",
@"com.google.Chrome"
];
llvm-svn: 193168
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Format/FormatToken.h | 19 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 12 |
3 files changed, 26 insertions, 11 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 18f0c33452d..16b1147fd58 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -562,11 +562,11 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, BreakBeforeParameter = true; } else { NewIndent = State.Stack.back().LastSpace; - if (Style.Cpp11BracedListStyle) - NewIndent += Style.ContinuationIndentWidth; - else { + if (Current.opensBlockTypeList(Style)) { NewIndent += Style.IndentWidth; ++NewIndentLevel; + } else { + NewIndent += Style.ContinuationIndentWidth; } } const FormatToken *NextNoComment = Current.getNextNonComment(); diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 52cc3ce530d..2001d427a69 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -339,15 +339,18 @@ struct FormatToken { return Tok; } + /// \brief Returns \c true if this tokens starts a block-type list, i.e. a + /// list that should be indented with a block indent. + bool opensBlockTypeList(const FormatStyle &Style) const { + return Type == TT_ArrayInitializerLSquare || + (is(tok::l_brace) && + (BlockKind == BK_Block || Type == TT_ObjCDictLiteral || + !Style.Cpp11BracedListStyle)); + } + + /// \brief Same as opensBlockTypeList, but for the closing token. bool closesBlockTypeList(const FormatStyle &Style) const { - if (is(tok::r_brace) && MatchingParen && - (MatchingParen->BlockKind == BK_Block || - !Style.Cpp11BracedListStyle)) - return true; - if (is(tok::r_square) && MatchingParen && - MatchingParen->Type == TT_ArrayInitializerLSquare) - return true; - return false; + return MatchingParen && MatchingParen->opensBlockTypeList(Style); } FormatToken *MatchingParen; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6dd94133922..d8ff2fcecaa 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5416,6 +5416,18 @@ TEST_F(FormatTest, ObjCLiterals) { " @\"--productid\",\n" " @\"com.google.Chrome\"\n" "];"); + verifyGoogleFormat( + "@{\n" + " NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : " + "regularFont,\n" + "};"); + verifyGoogleFormat( + "NSArray *arguments = @[\n" + " kind == kUserTicket ? @\"--user-store\" : @\"--system-store\",\n" + " @\"--print-tickets\",\n" + " @\"--productid\",\n" + " @\"com.google.Chrome\"\n" + "];"); } TEST_F(FormatTest, ReformatRegionAdjustsIndent) { |

