r222640 - clang-format: [Java] Space before array initializers.
Daniel Jasper
djasper at google.com
Sun Nov 23 12:54:38 PST 2014
Author: djasper
Date: Sun Nov 23 14:54:37 2014
New Revision: 222640
URL: http://llvm.org/viewvc/llvm-project?rev=222640&view=rev
Log:
clang-format: [Java] Space before array initializers.
Before:
new int[]{1, 2, 3, 4};
After:
new int[] {1, 2, 3, 4};
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222640&r1=222639&r2=222640&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Nov 23 14:54:37 2014
@@ -1712,6 +1712,8 @@ bool TokenAnnotator::spaceRequiredBefore
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))
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222640&r1=222639&r2=222640&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Nov 23 14:54:37 2014
@@ -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}");
More information about the cfe-commits
mailing list