Summary: Flag '= {' as a braced init list when parsing C# code.
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: cfe-commits, MyDeveloperDay
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D75760
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
+ // Block kind should probably be set to BK_BracedInit for any language.
+ // C# needs this change to ensure that array initialisers and object
+ // initialisers are indented the same way.
+ if (Style.isCSharp())
+ FormatTok->BlockKind = BK_BracedInit;
nextToken();
parseBracedList();
} else if (Style.Language == FormatStyle::LK_Proto &&
bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
tok::TokenKind ClosingBraceKind) {
bool HasError = false;
-
+
// FIXME: Once we have an expression parser in the UnwrappedLineParser,
// replace this by using parseAssigmentExpression() inside.
do {
Style);
}
+TEST_F(FormatTestCSharp, CSharpArrayInitializers) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+ verifyFormat(R"(//
+private MySet<Node>[] setPoints = {
+ new Point<Node>(),
+ new Point<Node>(),
+};)",
+ Style);
+}
+
TEST_F(FormatTestCSharp, CSharpNamedArguments) {
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);