[PATCH] D66662: [clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 26 08:41:15 PDT 2019
MyDeveloperDay updated this revision to Diff 217167.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66662/new/
https://reviews.llvm.org/D66662
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
@@ -165,6 +165,21 @@
"public string Host {\n set;\n get;\n}");
}
+TEST_F(FormatTestCSharp, CSharpUsing) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+ verifyFormat("public void foo() {\n"
+ " using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+ "}",
+ Style);
+
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+ verifyFormat("public void foo() {\n"
+ " using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+ "}",
+ Style);
+}
+
TEST_F(FormatTestCSharp, CSharpRegions) {
verifyFormat("#region aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaa long region");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,6 +2611,10 @@
return Style.Language == FormatStyle::LK_JavaScript ||
!Left.TokenText.endswith("=*/");
if (Right.is(tok::l_paren)) {
+ // using (FileStream fs...
+ if (Style.isCSharp() && Left.is(tok::kw_using) &&
+ Style.SpaceBeforeParens != FormatStyle::SBPO_Never)
+ return true;
if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
(Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66662.217167.patch
Type: text/x-patch
Size: 1693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190826/5a789f20/attachment.bin>
More information about the cfe-commits
mailing list