IDEA-25842 formatter gives multiple else-if branches too much indentation when using...
authorDenis Zhdanov <Denis.Zhdanov@jetbrains.com>
Tue, 27 Apr 2010 14:56:53 +0000 (18:56 +0400)
committerDenis Zhdanov <Denis.Zhdanov@jetbrains.com>
Tue, 27 Apr 2010 14:56:53 +0000 (18:56 +0400)
Added test for the ticket

java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormattingIndentationTest.java

index 8541193d8f3c6ad5e4305e49895fd940e6e8b112..41041af0646c0ff16b0e3012b2e6d371021c3afd 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.psi.formatter;
 
 import com.intellij.openapi.fileTypes.StdFileTypes;
+import com.intellij.psi.codeStyle.CodeStyleSettings;
 
 /**
  * Is intended to hold java formatting indentation-specific tests.
@@ -83,4 +84,43 @@ public class JavaFormattingIndentationTest extends AbstractJavaFormattingTest {
       "                                    .add(BigDecimal.ONE)))))))));"
     );
   }
+
+  public void testShiftedChainedIfElse() throws Exception {
+    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED2;
+    getSettings().ELSE_ON_NEW_LINE = true;
+    getSettings().getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 4;
+    doMethodTest(
+      "long a = System.currentTimeMillis();\n" +
+      "    if (a == 0){\n" +
+      "   }else if (a > 1){\n" +
+      "  }else if (a > 2){\n" +
+      " }else if (a > 3){\n" +
+      "     }else if (a > 4){\n" +
+      "      }else if (a > 5){\n" +
+      "       }else{\n" +
+      "        }",
+      "long a = System.currentTimeMillis();\n" +
+      "if (a == 0)\n" +
+      "    {\n" +
+      "    }\n" +
+      "else if (a > 1)\n" +
+      "    {\n" +
+      "    }\n" +
+      "else if (a > 2)\n" +
+      "    {\n" +
+      "    }\n" +
+      "else if (a > 3)\n" +
+      "    {\n" +
+      "    }\n" +
+      "else if (a > 4)\n" +
+      "    {\n" +
+      "    }\n" +
+      "else if (a > 5)\n" +
+      "    {\n" +
+      "    }\n" +
+      "else\n" +
+      "    {\n" +
+      "    }"
+    );
+  }
 }