[PATCH] D72401: Fixes for spaces around C# object initializers
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 31 06:33:25 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0bb60e29f18b: [clang-format] Fixes for spaces around C# object initializers (authored by Jonathan Coe <jbcoe at google.com>).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72401/new/
https://reviews.llvm.org/D72401
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -457,5 +457,34 @@
EXPECT_EQ(Code, format(Code, Style));
}
+TEST_F(FormatTestCSharp, CSharpObjectInitializers) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+ // Start code fragemnts with a comment line so that C++ raw string literals
+ // as seen are identical to expected formatted code.
+
+ verifyFormat(R"(//
+Shape[] shapes = new[] {
+ new Circle {
+ Radius = 2.7281,
+ Colour = Colours.Red,
+ },
+ new Square {
+ Side = 101.1,
+ Colour = Colours.Yellow,
+ },
+};)",
+ Style);
+
+ // Omitted final `,`s will change the formatting.
+ verifyFormat(R"(//
+Shape[] shapes = new[] {new Circle {Radius = 2.7281, Colour = Colours.Red},
+ new Square {
+ Side = 101.1,
+ Colour = Colours.Yellow,
+ }};)",
+ Style);
+}
+
} // namespace format
} // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2873,6 +2873,13 @@
if (Left.is(tok::kw_using))
return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements ||
spaceRequiredBeforeParens(Right);
+ // space between ']' and '{'
+ if (Left.is(tok::r_square) && Right.is(tok::l_brace))
+ return true;
+ // space before '{' in "new MyType {"
+ if (Right.is(tok::l_brace) && Left.Previous &&
+ Left.Previous->is(tok::kw_new))
+ return true;
} else if (Style.Language == FormatStyle::LK_JavaScript) {
if (Left.is(TT_JsFatArrow))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72401.241716.patch
Type: text/x-patch
Size: 1947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200131/d5cdbe1e/attachment.bin>
More information about the cfe-commits
mailing list