r193168 - clang-format: Fix ObjC literal indentation in Google style.
Daniel Jasper
djasper at google.com
Tue Oct 22 08:45:58 PDT 2013
Author: djasper
Date: Tue Oct 22 10:45:58 2013
New Revision: 193168
URL: http://llvm.org/viewvc/llvm-project?rev=193168&view=rev
Log:
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"
];
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=193168&r1=193167&r2=193168&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Oct 22 10:45:58 2013
@@ -562,11 +562,11 @@ unsigned ContinuationIndenter::moveState
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();
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=193168&r1=193167&r2=193168&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Tue Oct 22 10:45:58 2013
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=193168&r1=193167&r2=193168&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Oct 22 10:45:58 2013
@@ -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) {
More information about the cfe-commits
mailing list