This revision was automatically updated to reflect the committed changes. Closed by commit rL371720: [clang-format] [PR43100] clang-format C# support does not add a space between… (authored by paulhoad, committed by ). Herald added a project: LLVM.
Changed prior to commit: https://reviews.llvm.org/D66662?vs=217167&id=219873#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66662/new/ https://reviews.llvm.org/D66662 Files: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestCSharp.cpp Index: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/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; Index: cfe/trunk/unittests/Format/FormatTestCSharp.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestCSharp.cpp +++ cfe/trunk/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: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/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; Index: cfe/trunk/unittests/Format/FormatTestCSharp.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestCSharp.cpp +++ cfe/trunk/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");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits