aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestJava.cpp
diff options
context:
space:
mode:
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-01-07 10:02:45 +0100
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-01-07 10:06:49 +0100
commit91b9e6729c11cce8cf5fea727c6cb81ab8ab5ba4 (patch)
treeae556563aaccb14189b98cfd3d3d196e71fa6890 /clang/unittests/Format/FormatTestJava.cpp
parent01f355fe95f6b45db8bb239239b7ed978e094a13 (diff)
downloadllvm-91b9e6729c11cce8cf5fea727c6cb81ab8ab5ba4.zip
llvm-91b9e6729c11cce8cf5fea727c6cb81ab8ab5ba4.tar.gz
llvm-91b9e6729c11cce8cf5fea727c6cb81ab8ab5ba4.tar.bz2
[clang-format] Fix `BraceWrapping: AfterFunction` affecting synchronized blocks in Java.
Fixes https://github.com/llvm/llvm-project/issues/32031. Before this change, BraceWrapping: AfterFunction would affect synchronized blocks in Java, but they should be formatted w.r.t. BraceWrapping: AfterControlStatement. Using the config: ``` BreakBeforeBraces: Custom BraceWrapping: AfterControlStatement: false AfterFunction: true ``` would result in misformatted code like: ``` class Foo { void bar() { synchronized (this) { a(); a(); } } } ``` instead of: ``` class Foo { void bar() { synchronized (this) { a(); a(); } } } ``` Reviewed By: MyDeveloperDay, owenpan Differential Revision: https://reviews.llvm.org/D116767
Diffstat (limited to 'clang/unittests/Format/FormatTestJava.cpp')
-rw-r--r--clang/unittests/Format/FormatTestJava.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp
index 9a18c28..84f6420 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -431,6 +431,24 @@ TEST_F(FormatTestJava, SynchronizedKeyword) {
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) {