clang-format: [Java] Space before array initializers.
authorDaniel Jasper <djasper@google.com>
Sun, 23 Nov 2014 20:54:37 +0000 (20:54 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 23 Nov 2014 20:54:37 +0000 (20:54 +0000)
Before:
  new int[]{1, 2, 3, 4};

After:
  new int[] {1, 2, 3, 4};

llvm-svn: 222640

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestJava.cpp

index a36f9630e6860a011fa73beb430c7adeb8b2bedc..e36a16a54a1de4a948444fab7b3315ff0d50201a 100644 (file)
@@ -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))
index 8c9504b1c1bc6d45481a2021f92e043f57c6136e..ba91f1677bfc78c5ffe3fe19e0caaa3c3500dc98 100644 (file)
@@ -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}");