forked from OSchip/llvm-project
[clang-format] Do not format C# array subscript operators as attributes
Summary: Fix misidentification of C# array subscript operators. Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits, MyDeveloperDay Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D75517
This commit is contained in:
parent
900dee8c8e
commit
736fef97c7
clang
|
@ -369,6 +369,17 @@ private:
|
||||||
if (!Style.isCSharp())
|
if (!Style.isCSharp())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// `identifier[i]` is not an attribute.
|
||||||
|
if (Tok.Previous && Tok.Previous->is(tok::identifier))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Chains [] in of `identifier[i][j][k]` are not attributes.
|
||||||
|
if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
|
||||||
|
auto *MatchingParen = Tok.Previous->MatchingParen;
|
||||||
|
if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const FormatToken *AttrTok = Tok.Next;
|
const FormatToken *AttrTok = Tok.Next;
|
||||||
if (!AttrTok)
|
if (!AttrTok)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -628,5 +628,13 @@ TEST_F(FormatTestCSharp, CSharpNullableTypes) {
|
||||||
Style); // An array of a nullable type.
|
Style); // An array of a nullable type.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(FormatTestCSharp, CSharpArraySubscripts) {
|
||||||
|
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
|
||||||
|
|
||||||
|
// Do not format array subscript operators as attributes.
|
||||||
|
verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
|
||||||
|
verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace format
|
} // namespace format
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
Loading…
Reference in New Issue