This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. Closed by commit rG015bca3e67cb: [clang-format] C# property formatting can be controlled by config options (authored by Jonathan Coe <jb...@google.com>).
Changed prior to commit: https://reviews.llvm.org/D79000?vs=260610&id=260672#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79000/new/ https://reviews.llvm.org/D79000 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestCSharp.cpp Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -245,11 +245,13 @@ "}"); verifyFormat("[TestMethod]\n" - "public string Host { set; get; }"); + "public string Host\n" + "{ set; get; }"); verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server " "listening on provided host\")]\n" - "public string Host { set; get; }"); + "public string Host\n" + "{ set; get; }"); verifyFormat( "[DllImport(\"Hello\", EntryPoint = \"hello_world\")]\n" @@ -671,6 +673,32 @@ DefaultThirdArgument); })", Style); + + // Brace wrapping and single-lining of accessor can be controlled by config. + Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + + verifyFormat(R"(// +public class SaleItem { + public decimal Price + { get; set; } +})", + Style); + + verifyFormat(R"(// +class TimePeriod { + public double Hours + { + get { + return _seconds / 3600; + } + set { + _seconds = value * 3600; + } + } +})", + Style); } TEST_F(FormatTestCSharp, CSharpSpaces) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1531,6 +1531,8 @@ // Try to parse the property accessor: // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties Tokens->setPosition(StoredPosition); + if (Style.BraceWrapping.AfterFunction == true) + addUnwrappedLine(); nextToken(); do { switch (FormatTok->Tok.getKind()) {
Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -245,11 +245,13 @@ "}"); verifyFormat("[TestMethod]\n" - "public string Host { set; get; }"); + "public string Host\n" + "{ set; get; }"); verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server " "listening on provided host\")]\n" - "public string Host { set; get; }"); + "public string Host\n" + "{ set; get; }"); verifyFormat( "[DllImport(\"Hello\", EntryPoint = \"hello_world\")]\n" @@ -671,6 +673,32 @@ DefaultThirdArgument); })", Style); + + // Brace wrapping and single-lining of accessor can be controlled by config. + Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterFunction = true; + + verifyFormat(R"(// +public class SaleItem { + public decimal Price + { get; set; } +})", + Style); + + verifyFormat(R"(// +class TimePeriod { + public double Hours + { + get { + return _seconds / 3600; + } + set { + _seconds = value * 3600; + } + } +})", + Style); } TEST_F(FormatTestCSharp, CSharpSpaces) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1531,6 +1531,8 @@ // Try to parse the property accessor: // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties Tokens->setPosition(StoredPosition); + if (Style.BraceWrapping.AfterFunction == true) + addUnwrappedLine(); nextToken(); do { switch (FormatTok->Tok.getKind()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits