[PATCH] D116767: [clang-format] Fix `BraceWrapping: AfterFunction` affecting synchronized blocks in Java.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 01:07:07 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91b9e6729c11: [clang-format] Fix `BraceWrapping: AfterFunction` affecting synchronized blocks… (authored by curdeius).
Changed prior to commit:
https://reviews.llvm.org/D116767?vs=397987&id=398074#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116767/new/
https://reviews.llvm.org/D116767
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestJava.cpp
Index: clang/unittests/Format/FormatTestJava.cpp
===================================================================
--- clang/unittests/Format/FormatTestJava.cpp
+++ clang/unittests/Format/FormatTestJava.cpp
@@ -431,6 +431,24 @@
verifyFormat("synchronized (mData) {\n"
" // ...\n"
"}");
+
+ FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java);
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+
+ Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Always;
+ Style.BraceWrapping.AfterFunction = false;
+ verifyFormat("synchronized (mData)\n"
+ "{\n"
+ " // ...\n"
+ "}",
+ Style);
+
+ Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Never;
+ Style.BraceWrapping.AfterFunction = true;
+ verifyFormat("synchronized (mData) {\n"
+ " // ...\n"
+ "}",
+ Style);
}
TEST_F(FormatTestJava, AssertKeyword) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1523,8 +1523,16 @@
// structural element.
// FIXME: Figure out cases where this is not true, and add projections
// for them (the one we know is missing are lambdas).
- if (Style.BraceWrapping.AfterFunction)
+ if (Style.Language == FormatStyle::LK_Java &&
+ Line->Tokens.front().Tok->is(Keywords.kw_synchronized)) {
+ // If necessary, we could set the type to something different than
+ // TT_FunctionLBrace.
+ if (Style.BraceWrapping.AfterControlStatement ==
+ FormatStyle::BWACS_Always)
+ addUnwrappedLine();
+ } else if (Style.BraceWrapping.AfterFunction) {
addUnwrappedLine();
+ }
FormatTok->setType(TT_FunctionLBrace);
parseBlock();
addUnwrappedLine();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116767.398074.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220107/8d1853dc/attachment.bin>
More information about the cfe-commits
mailing list