diff options
| author | Paul Hoad <mydeveloperday@gmail.com> | 2019-09-12 10:18:53 +0000 |
|---|---|---|
| committer | Paul Hoad <mydeveloperday@gmail.com> | 2019-09-12 10:18:53 +0000 |
| commit | 719087bbb775d49f6f4c3f923bb3282b66e588ce (patch) | |
| tree | 2292d92acefb452b802017bffea8f95e51401a00 | |
| parent | 3867a2d51076494a19c02a2d5c4e4167bd6cbe0e (diff) | |
| download | bcm5719-llvm-719087bbb775d49f6f4c3f923bb3282b66e588ce.tar.gz bcm5719-llvm-719087bbb775d49f6f4c3f923bb3282b66e588ce.zip | |
[clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
Summary:
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100
Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is !
```
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
this change simply overcomes this for when using C# settings in the .clang-format file
```
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
```
All FormatTests pass..
```
[==========] 688 tests from 21 test cases ran. (88508 ms total)
[ PASSED ] 688 tests.
```
Reviewers: djasper, klimek, owenpan
Reviewed By: owenpan
Subscribers: llvm-commits, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66662
llvm-svn: 371720
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 4 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 15 |
2 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 5be398565c9..55ab654f960 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2611,6 +2611,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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; diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 801adb28bd9..7fda9566dc8 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -165,6 +165,21 @@ TEST_F(FormatTestCSharp, Attributes) { "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"); |

