Author: Jonathan Coe Date: 2020-02-05T17:38:33Z New Revision: f40a7972cb42e130c6e954f21acf9b66bf5bcad7
URL: https://github.com/llvm/llvm-project/commit/f40a7972cb42e130c6e954f21acf9b66bf5bcad7 DIFF: https://github.com/llvm/llvm-project/commit/f40a7972cb42e130c6e954f21acf9b66bf5bcad7.diff LOG: [clang-format] Do not merge short C# class definitions into one line Summary: Skip access specifiers before record definitions when deciding whether or not to wrap lines so that C# class definitions do not get wrapped into a single line. Reviewers: krasimir, MyDeveloperDay Reviewed By: krasimir Tags: #clang-format Differential Revision: https://reviews.llvm.org/D74050 Added: Modified: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTestCSharp.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index fec85f1174da..0e1b5e95e9dd 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -593,9 +593,10 @@ class LineJoiner { FormatToken *RecordTok = Line.First; // Skip record modifiers. while (RecordTok->Next && - RecordTok->isOneOf(tok::kw_typedef, tok::kw_export, - Keywords.kw_declare, Keywords.kw_abstract, - tok::kw_default)) + RecordTok->isOneOf( + tok::kw_typedef, tok::kw_export, Keywords.kw_declare, + Keywords.kw_abstract, tok::kw_default, tok::kw_public, + tok::kw_private, tok::kw_protected, Keywords.kw_internal)) RecordTok = RecordTok->Next; if (RecordTok && RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct, diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index dba76b521614..918f8aed83e9 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -70,6 +70,30 @@ TEST_F(FormatTestCSharp, CSharpClass) { " f();\n" " }\n" "}"); + + // Ensure that small and empty classes are handled correctly with condensed + // (Google C++-like) brace-breaking style. + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + Style.BreakBeforeBraces = FormatStyle::BS_Attach; + + verifyFormat("public class SomeEmptyClass {}", Style); + + verifyFormat("public class SomeTinyClass {\n" + " int X;\n" + "}", + Style); + verifyFormat("private class SomeTinyClass {\n" + " int X;\n" + "}", + Style); + verifyFormat("protected class SomeTinyClass {\n" + " int X;\n" + "}", + Style); + verifyFormat("internal class SomeTinyClass {\n" + " int X;\n" + "}", + Style); } TEST_F(FormatTestCSharp, AccessModifiers) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits