From 4efe2c94ef9cc88721e28b0b72ae5abc4b6fdcdc Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 23 Nov 2014 20:54:37 +0000 Subject: [PATCH] clang-format: [Java] Space before array initializers. Before: new int[]{1, 2, 3, 4}; After: new int[] {1, 2, 3, 4}; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222640 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 ++ unittests/Format/FormatTestJava.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index a36f9630e6..e36a16a54a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1712,6 +1712,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if (Left.is(Keywords.kw_var)) return true; } else if (Style.Language == FormatStyle::LK_Java) { + if (Left.is(tok::r_square) && Right.is(tok::l_brace)) + return true; if (Left.is(TT_LambdaArrow) || Right.is(TT_LambdaArrow)) return true; if (Left.is(Keywords.kw_synchronized) && Right.is(tok::l_paren)) diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 8c9504b1c1..ba91f1677b 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -144,8 +144,8 @@ TEST_F(FormatTestJava, EnumDeclarations) { " }\n" "}"); verifyFormat("enum SomeThing {\n" - " ABC(new int[]{1, 2}),\n" - " CDE(new int[]{2, 3});\n" + " ABC(new int[] {1, 2}),\n" + " CDE(new int[] {2, 3});\n" " Something(int[] i) {\n" " }\n" "}"); @@ -180,6 +180,13 @@ TEST_F(FormatTestJava, EnumDeclarations) { "}"); } +TEST_F(FormatTestJava, ArrayInitializers) { + verifyFormat("new int[] {1, 2, 3, 4};"); + verifyFormat("new int[] {\n" + " 1, 2, 3, 4,\n" + "};"); +} + TEST_F(FormatTestJava, ThrowsDeclarations) { verifyFormat("public void doSooooooooooooooooooooooooooomething()\n" " throws LooooooooooooooooooooooooooooongException {\n}"); -- 2.40.0