replaced <code></code> with more concise {@code}
[idea/community.git] / java / java-tests / testSrc / com / intellij / java / psi / formatter / java / JavaFormatterAlignmentTest.java
1 /*
2  * Copyright 2000-2017 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.java.psi.formatter.java;
17
18 import com.intellij.openapi.fileTypes.StdFileTypes;
19 import com.intellij.openapi.util.TextRange;
20 import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
21 import com.intellij.util.IncorrectOperationException;
22
23 import static com.intellij.formatting.FormatterTestUtils.Action.REFORMAT_WITH_CONTEXT;
24
25 /**
26  * Is intended to hold specific java formatting tests for alignment settings (
27  * {@code Project Settings - Code Style - Alignment and Braces}).
28  *
29  * @author Denis Zhdanov
30  * @since Apr 27, 2010 6:42:00 PM
31  */
32 public class JavaFormatterAlignmentTest extends AbstractJavaFormatterTest {
33
34   public void testChainedMethodsAlignment() throws Exception {
35     // Inspired by IDEA-30369
36     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
37     getSettings().METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
38     getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 8;
39     doTest();
40   }
41
42   public void testMethodAndChainedField() throws Exception {
43     // Inspired by IDEA-79806
44
45     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
46     doMethodTest(
47       "Holder.INSTANCE\n" +
48       "                .foo();",
49       "Holder.INSTANCE\n" +
50       "        .foo();"
51     );
52   }
53   
54   public void testChainedMethodWithComments() throws Exception {
55     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
56     doMethodTest("AAAAA.b()\n" +
57                  ".c() // comment after line\n" +
58                  ".d()\n" +
59                  ".e();",
60
61                  "AAAAA.b()\n" +
62                  "     .c() // comment after line\n" +
63                  "     .d()\n" +
64                  "     .e();");
65   }
66
67   public void testChainedMethodWithBlockComment() {
68     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
69     doTextTest("class X {\n" +
70                "    public void test() {\n" +
71                "        AAAAAA.b()\n" +
72                ".c()\n" +
73                ".d()\n" +
74                "          /* simple block comment */\n" +
75                ".e();\n" +
76                "    }\n" +
77                "}",
78                "class X {\n" +
79                "    public void test() {\n" +
80                "        AAAAAA.b()\n" +
81                "              .c()\n" +
82                "              .d()\n" +
83                "              /* simple block comment */\n" +
84                "              .e();\n" +
85                "    }\n" +
86                "}");
87   }
88   
89   public void testMultipleMethodAnnotationsCommentedInTheMiddle() throws Exception {
90     getSettings().BLANK_LINES_AFTER_CLASS_HEADER = 1;
91     getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 4;
92
93     // Inspired by IDEA-53942
94     doTextTest(
95       "public class Test {\n" +
96       "          @Override\n" +
97       "//       @XmlElement(name = \"Document\", required = true, type = DocumentType.class)\n" +
98       "       @XmlTransient\n" +
99       "  void foo() {\n" +
100       "}\n" +
101       "}",
102
103       "public class Test {\n" +
104       "\n" +
105       "    @Override\n" +
106       "//       @XmlElement(name = \"Document\", required = true, type = DocumentType.class)\n" +
107       "    @XmlTransient\n" +
108       "    void foo() {\n" +
109       "    }\n" +
110       "}"
111     );
112   }
113
114   public void testTernaryOperator() throws Exception {
115     // Inspired by IDEADEV-13018
116     getSettings().ALIGN_MULTILINE_TERNARY_OPERATION = true;
117
118     doMethodTest("int i = a ? x\n" + ": y;", "int i = a ? x\n" + "          : y;");
119   }
120
121   public void testMethodCallArgumentsAndSmartTabs() throws IncorrectOperationException {
122     // Inspired by IDEADEV-20144.
123     getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
124     getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
125     getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
126     doTextTest("class Foo {\n" +
127                "    void foo() {\n" +
128                "        bar(new Object[] {\n" +
129                "            \"hello1\",\n" +
130                "            \"hello2\", add(\"hello3\",\n" +
131                "                           \"world\")\n" +
132                "});" +
133                "    }}", "class Foo {\n" +
134                          "\tvoid foo() {\n" +
135                          "\t\tbar(new Object[]{\n" +
136                          "\t\t\t\t\"hello1\",\n" +
137                          "\t\t\t\t\"hello2\", add(\"hello3\",\n" +
138                          "\t\t\t\t              \"world\")\n" +
139                          "\t\t});\n" +
140                          "\t}\n" +
141                          "}");
142   }
143
144   public void testArrayInitializer() throws IncorrectOperationException {
145     // Inspired by IDEADEV-16136
146     getSettings().ARRAY_INITIALIZER_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;
147     getSettings().ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION = true;
148
149     doTextTest(
150       "@SuppressWarnings({\"UseOfSystemOutOrSystemErr\", \"AssignmentToCollectionOrArrayFieldFromParameter\", \"ReturnOfCollectionOrArrayField\"})\n" +
151       "public class Some {\n" +
152       "}",
153       "@SuppressWarnings({\"UseOfSystemOutOrSystemErr\",\n" +
154       "                   \"AssignmentToCollectionOrArrayFieldFromParameter\",\n" +
155       "                   \"ReturnOfCollectionOrArrayField\"})\n" +
156       "public class Some {\n" +
157       "}");
158   }
159
160   public void testMethodBrackets() throws Exception {
161     // Inspired by IDEA-53013
162     getSettings().ALIGN_MULTILINE_METHOD_BRACKETS = true;
163     getSettings().ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION = false;
164     getSettings().ALIGN_MULTILINE_PARAMETERS = true;
165     getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
166     getSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
167     getSettings().METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
168
169     doClassTest(
170       "public void foo(int i,\n" +
171       "                  int j) {\n" +
172       "}\n" +
173       "\n" +
174       "  public void bar() {\n" +
175       "    foo(1,\n" +
176       "        2);\n" +
177       "  }",
178
179       "public void foo(int i,\n" +
180       "                int j\n" +
181       "               ) {\n" +
182       "}\n" +
183       "\n" +
184       "public void bar() {\n" +
185       "    foo(1,\n" +
186       "        2\n" +
187       "       );\n" +
188       "}"
189     );
190
191     // Inspired by IDEA-55306
192     getSettings().ALIGN_MULTILINE_METHOD_BRACKETS = false;
193     getSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = false;
194     String method =
195       "executeCommand(new Command<Boolean>() {\n" +
196       "    public Boolean run() throws ExecutionException {\n" +
197       "        return doInterrupt();\n" +
198       "    }\n" +
199       "});";
200     doMethodTest(method, method);
201   }
202
203   public void testFieldInColumnsAlignment() {
204     // Inspired by IDEA-55147
205     getSettings().ALIGN_GROUP_FIELD_DECLARATIONS = true;
206     getSettings().FIELD_ANNOTATION_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
207     getSettings().VARIABLE_ANNOTATION_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
208
209     doTextTest(
210       "public class FormattingTest {\n" +
211       "\n" +
212       "    int start = 1;\n" +
213       "    double end = 2;\n" +
214       "\n" +
215       "    int i2 = 1;\n" +
216       "    double dd2,\n" +
217       "        dd3 = 2;\n" +
218       "\n" +
219       "    // asd\n" +
220       "    char ccc3 = 'a';\n" +
221       "    double ddd31, ddd32 = 1;\n" +
222       "\n" +
223       "    private\n" +
224       "    final String s4 = \"\";\n" +
225       "    private\n" +
226       "    transient int i4 = 1;\n" +
227       "\n" +
228       "    private final String s5 = \"xxx\";\n" +
229       "    private transient int iiii5 = 1;\n" +
230       "    /*sdf*/\n" +
231       "    @MyAnnotation(value = 1, text = 2) float f5 = 1;\n" +
232       "}",
233
234       "public class FormattingTest {\n" +
235       "\n" +
236       "    int    start = 1;\n" +
237       "    double end   = 2;\n" +
238       "\n" +
239       "    int    i2   = 1;\n" +
240       "    double dd2,\n" +
241       "            dd3 = 2;\n" +
242       "\n" +
243       "    // asd\n" +
244       "    char   ccc3         = 'a';\n" +
245       "    double ddd31, ddd32 = 1;\n" +
246       "\n" +
247       "    private\n" +
248       "    final     String s4 = \"\";\n" +
249       "    private\n" +
250       "    transient int    i4 = 1;\n" +
251       "\n" +
252       "    private final                      String s5    = \"xxx\";\n" +
253       "    private transient                  int    iiii5 = 1;\n" +
254       "    /*sdf*/\n" +
255       "    @MyAnnotation(value = 1, text = 2) float  f5    = 1;\n" +
256       "}"
257     );
258   }
259
260   public void testTabsAndFieldsInColumnsAlignment() throws Exception {
261     // Inspired by IDEA-56242
262     getSettings().ALIGN_GROUP_FIELD_DECLARATIONS = true;
263     getIndentOptions().USE_TAB_CHARACTER = true;
264
265     doTextTest(
266       "public class Test {\n" +
267         "\tprivate Long field2 = null;\n" +
268         "\tprivate final Object field1 = null;\n" +
269         "\tprivate int i = 1;\n" +
270       "}",
271
272       "public class Test {\n" +
273         "\tprivate       Long   field2 = null;\n" +
274         "\tprivate final Object field1 = null;\n" +
275         "\tprivate       int    i      = 1;\n" +
276       "}"
277     );
278   }
279
280   public void testDoNotAlignIfNotEnabled() {
281     getSettings().ALIGN_GROUP_FIELD_DECLARATIONS = false;
282     doTextTest(
283       "public class Test {\n" +
284       "private Long field2 = null;\n" +
285       "private final Object field1 = null;\n" +
286       "private int i = 1;\n" +
287       "}",
288
289       "public class Test {\n" +
290       "    private Long field2 = null;\n" +
291       "    private final Object field1 = null;\n" +
292       "    private int i = 1;\n" +
293       "}"
294     );
295   }
296
297   public void testAnnotatedAndNonAnnotatedFieldsInColumnsAlignment() {
298     // Inspired by IDEA-60237
299
300     getSettings().ALIGN_GROUP_FIELD_DECLARATIONS = true;
301     doTextTest(
302       "public class Test {\n" +
303       "    @Id\n" +
304       "    private final String name;\n" +
305       "    @Column(length = 2 * 1024 * 1024 /* 2 MB */)\n" +
306       "    private String value;\n" +
307       "    private boolean required;\n" +
308       "    private String unsetValue;\n" +
309       "}",
310
311       "public class Test {\n" +
312       "    @Id\n" +
313       "    private final String  name;\n" +
314       "    @Column(length = 2 * 1024 * 1024 /* 2 MB */)\n" +
315       "    private       String  value;\n" +
316       "    private       boolean required;\n" +
317       "    private       String  unsetValue;\n" +
318       "}"
319     );
320   }
321
322   public void testAlignThrowsKeyword() throws Exception {
323     // Inspired by IDEA-63820
324
325     getSettings().ALIGN_THROWS_KEYWORD = true;
326     doClassTest(
327       "public void test()\n" +
328       "                 throws Exception {}",
329       "public void test()\n" +
330       "throws Exception {\n" +
331       "}"
332     );
333
334     getSettings().ALIGN_THROWS_KEYWORD = false;
335     doClassTest(
336       "public void test()\n" +
337       "                 throws Exception {}",
338       "public void test()\n" +
339       "        throws Exception {\n" +
340       "}"
341     );
342   }
343
344   public void testAlignResourceList() throws Exception {
345     getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
346
347     getSettings().ALIGN_MULTILINE_RESOURCES = true;
348     doMethodTest("try (MyResource r1 = null;\n" +
349                  "MyResource r2 = null) { }",
350                  "try (MyResource r1 = null;\n" +
351                  "     MyResource r2 = null) { }");
352
353     getSettings().ALIGN_MULTILINE_RESOURCES = false;
354     doMethodTest("try (MyResource r1 = null;\n" +
355                  "MyResource r2 = null) { }",
356                  "try (MyResource r1 = null;\n" +
357                  "        MyResource r2 = null) { }");
358   }
359
360
361   public void testChainedMethodCallsAfterFieldsChain_WithAlignment() throws Exception {
362     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
363     getSettings().METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;
364
365     doMethodTest(
366       "a.current.current.current.getThis().getThis().getThis();",
367
368       "a.current.current.current.getThis()\n" +
369       "                         .getThis()\n" +
370       "                         .getThis();"
371     );
372
373     doMethodTest(
374       "a.current.current.current.getThis().getThis().getThis().current.getThis().getThis().getThis().getThis();",
375
376       "a.current.current.current.getThis()\n" +
377       "                         .getThis()\n" +
378       "                         .getThis().current.getThis()\n" +
379       "                                           .getThis()\n" +
380       "                                           .getThis()\n" +
381       "                                           .getThis();"
382     );
383
384
385     String onlyMethodCalls = "getThis().getThis().getThis();";
386     String formatedMethodCalls = "getThis().getThis()\n" +
387                                  "         .getThis();";
388
389     doMethodTest(onlyMethodCalls, formatedMethodCalls);
390   }
391
392   public void testChainedMethodCallsAfterFieldsChain_WithoutAlignment() throws Exception {
393     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = false;
394     getSettings().METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS;
395
396     doMethodTest(
397       "a.current.current.current.getThis().getThis().getThis();",
398
399       "a.current.current.current.getThis()\n" +
400       "        .getThis()\n" +
401       "        .getThis();"
402     );
403   }
404
405   public void testChainedMethodCalls_WithChopDownIfLongOption() throws Exception {
406     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
407     getSettings().METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM; // it's equal to "Chop down if long"
408     getSettings().RIGHT_MARGIN = 50;
409
410     String before = "a.current.current.getThis().getThis().getThis().getThis().getThis();";
411     doMethodTest(
412       before,
413       "a.current.current.getThis()\n" +
414       "                 .getThis()\n" +
415       "                 .getThis()\n" +
416       "                 .getThis()\n" +
417       "                 .getThis();"
418     );
419
420     getSettings().RIGHT_MARGIN = 80;
421     doMethodTest(before, before);
422   }
423
424   public void testChainedMethodCalls_WithWrapIfNeededOption() throws Exception {
425     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = false;
426     getSettings().METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
427     getSettings().RIGHT_MARGIN = 50;
428
429     String before = "a.current.current.getThis().getThis().getThis().getThis();";
430
431     doMethodTest(
432       before,
433       "a.current.current.getThis().getThis()\n" +
434       "        .getThis().getThis();"
435     );
436
437     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
438
439     doMethodTest(
440       before,
441       "a.current.current.getThis().getThis()\n" +
442       "                 .getThis().getThis();"
443     );
444
445     getSettings().RIGHT_MARGIN = 75;
446     doMethodTest(before, before);
447   }
448
449   public void testAlignMethodCalls_PassedAsParameters_InMethodCall() {
450     getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
451
452     doMethodTest(
453       "test(call1(),\n" +
454       "             call2(),\n" +
455       "                        call3());\n",
456       "test(call1(),\n" +
457       "     call2(),\n" +
458       "     call3());\n"
459     );
460   }
461
462   public void testLocalVariablesAlignment() {
463     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
464     doMethodTest(
465       "int a = 2;\n" +
466       "String myString = \"my string\"",
467       "int    a        = 2;\n" +
468       "String myString = \"my string\""
469     );
470   }
471
472   public void testAlignOnlyDeclarationStatements() {
473     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
474     doMethodTest(
475       "      String s;\n" +
476       "   int a = 2;\n" +
477       "s = \"abs\";\n" +
478       "long stamp = 12;",
479       "String s;\n" +
480       "int    a = 2;\n" +
481       "s = \"abs\";\n" +
482       "long stamp = 12;"
483     );
484   }
485
486   public void testDoNotAlignWhenBlankLine() {
487     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
488     doMethodTest(
489       "int a = 2;\n" +
490       "\n" +
491       "String myString = \"my string\"",
492       "int a = 2;\n" +
493       "\n" +
494       "String myString = \"my string\""
495     );
496   }
497
498   public void testDoNotAlignWhenGroupInterrupted() {
499     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
500     doMethodTest(
501       "int a = 2;\n" +
502       "System.out.println(\"hi!\")\n" +
503       "String myString = \"my string\"",
504       "int a = 2;\n" +
505       "System.out.println(\"hi!\")\n" +
506       "String myString = \"my string\""
507     );
508   }
509
510   public void testDoNotAlignMultiDeclarations() {
511     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
512     doMethodTest(
513       "  int a, b = 2;\n" +
514       "String myString = \"my string\"",
515       "int    a, b     = 2;\n" +
516       "String myString = \"my string\""
517     );
518   }
519
520   public void testDoNotAlignMultilineParams() {
521     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
522
523     doMethodTest(
524       "int a = 12;\n" +
525       "  Runnable runnable = new Runnable() {\n" +
526       "    @Override\n" +
527       "    public void run() {\n" +
528       "        System.out.println(\"AAA!\");\n" +
529       "    }\n" +
530       "};",
531
532       "int a = 12;\n" +
533       "Runnable runnable = new Runnable() {\n" +
534       "    @Override\n" +
535       "    public void run() {\n" +
536       "        System.out.println(\"AAA!\");\n" +
537       "    }\n" +
538       "};"
539     );
540
541     doMethodTest(
542       "   Runnable runnable = new Runnable() {\n" +
543       "    @Override\n" +
544       "    public void run() {\n" +
545       "        System.out.println(\"AAA!\");\n" +
546       "    }\n" +
547       "};\n" +
548       "int c = 12;",
549
550       "Runnable runnable = new Runnable() {\n" +
551       "    @Override\n" +
552       "    public void run() {\n" +
553       "        System.out.println(\"AAA!\");\n" +
554       "    }\n" +
555       "};\n" +
556       "int c = 12;"
557     );
558
559     doMethodTest(
560       "    int ac = 99;\n" +
561       "Runnable runnable = new Runnable() {\n" +
562       "    @Override\n" +
563       "    public void run() {\n" +
564       "        System.out.println(\"AAA!\");\n" +
565       "    }\n" +
566       "};\n" +
567       "int c = 12;",
568
569       "int ac = 99;\n" +
570       "Runnable runnable = new Runnable() {\n" +
571       "    @Override\n" +
572       "    public void run() {\n" +
573       "        System.out.println(\"AAA!\");\n" +
574       "    }\n" +
575       "};\n" +
576       "int c = 12;"
577     );
578   }
579
580   public void testDoNotAlign_IfFirstMultiline() {
581     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
582
583     doMethodTest(
584       "int\n" +
585       "       i = 0;\n" +
586       "int[] a = new int[]{1, 2, 0x0052, 0x0053, 0x0054};\n" +
587       "int var1 = 1;\n" +
588       "int var2 = 2;",
589
590       "int\n" +
591       "        i = 0;\n" +
592       "int[] a    = new int[]{1, 2, 0x0052, 0x0053, 0x0054};\n" +
593       "int   var1 = 1;\n" +
594       "int   var2 = 2;"
595     );
596   }
597
598   public void testAlign_InMethod() {
599     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
600     doClassTest(
601       "public void run() {\n" +
602       "\n" +
603       "                int a = 2;\n" +
604       "            String superString = \"\";\n" +
605       "\n" +
606       "     test(call1(), call2(), call3());\n" +
607       "    }",
608
609       "public void run() {\n" +
610       "\n" +
611       "    int    a           = 2;\n" +
612       "    String superString = \"\";\n" +
613       "\n" +
614       "    test(call1(), call2(), call3());\n" +
615       "}"
616     );
617
618     doClassTest(
619       "public void run() {\n" +
620       "\n" +
621       "        test(call1(), call2(), call3());\n" +
622       "\n" +
623       "        int a = 2;\n" +
624       "             String superString = \"\";\n" +
625       "}",
626       "public void run() {\n" +
627       "\n" +
628       "    test(call1(), call2(), call3());\n" +
629       "\n" +
630       "    int    a           = 2;\n" +
631       "    String superString = \"\";\n" +
632       "}");
633   }
634
635   public void test_Shift_All_AlignedParameters() {
636     myLineRange = new TextRange(2, 2);
637     getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
638     doTextTest(
639       REFORMAT_WITH_CONTEXT,
640       "public class Test {\n" +
641       "  \n" +
642       "    public void fooooo(String foo,\n" +
643       "                    String booo,\n" +
644       "                    String kakadoo) {\n" +
645       "\n" +
646       "    }\n" +
647       "\n" +
648       "}",
649
650       "public class Test {\n" +
651       "\n" +
652       "    public void fooooo(String foo,\n" +
653       "                       String booo,\n" +
654       "                       String kakadoo) {\n" +
655       "\n" +
656       "    }\n" +
657       "\n" +
658       "}"
659     );
660   }
661
662   public void test_Align_UnselectedField_IfNeeded() {
663     myLineRange = new TextRange(2, 2);
664     getSettings().ALIGN_GROUP_FIELD_DECLARATIONS = true;
665     doTextTest(
666       REFORMAT_WITH_CONTEXT,
667       "public class Test {\n" +
668       "    public int    i = 1;\n" +
669       "    public String iiiiiiiiii = 2;\n" +
670       "}",
671       "public class Test {\n" +
672       "    public int    i          = 1;\n" +
673       "    public String iiiiiiiiii = 2;\n" +
674       "}"
675     );
676   }
677
678   public void test_Align_UnselectedVariable_IfNeeded() {
679     myLineRange = new TextRange(3, 3);
680     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
681     doTextTest(
682       REFORMAT_WITH_CONTEXT,
683       "public class Test {\n" +
684       "    public void test() {\n" +
685       "        int s = 2;\n" +
686       "        String sssss = 3;\n" +
687       "    }\n" +
688       "}",
689       "public class Test {\n" +
690       "    public void test() {\n" +
691       "        int    s     = 2;\n" +
692       "        String sssss = 3;\n" +
693       "    }\n" +
694       "}"
695     );
696   }
697
698   public void test_Align_ConsecutiveVars_InsideIfBlock() {
699     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
700     doMethodTest(
701       "if (a > 2) {\n" +
702       "int a=2;\n" +
703       "String name=\"Yarik\";\n" +
704       "}\n",
705       "if (a > 2) {\n" +
706       "    int    a    = 2;\n" +
707       "    String name = \"Yarik\";\n" +
708       "}\n"
709     );
710   }
711
712   public void test_Align_ConsecutiveVars_InsideForBlock() {
713     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
714     doMethodTest(
715       "    for (int i = 0; i < 10; i++) {\n" +
716       "      int a=2;\n" +
717       "      String name=\"Xa\";\n" +
718       "    }\n",
719       "for (int i = 0; i < 10; i++) {\n" +
720       "    int    a    = 2;\n" +
721       "    String name = \"Xa\";\n" +
722       "}\n"
723     );
724   }
725
726   public void test_Align_ConsecutiveVars_InsideTryBlock() {
727     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
728     doMethodTest(
729       "    try {\n" +
730       "      int x = getX();\n" +
731       "      String name = \"Ha\";\n" +
732       "    }\n" +
733       "    catch (IOException exception) {\n" +
734       "      int y = 12;\n" +
735       "      String test = \"Test\";\n" +
736       "    }\n" +
737       "    finally {\n" +
738       "      int z = 12;\n" +
739       "      String zzzz = \"pnmhd\";\n" +
740       "    }\n",
741       "try {\n" +
742       "    int    x    = getX();\n" +
743       "    String name = \"Ha\";\n" +
744       "} catch (IOException exception) {\n" +
745       "    int    y    = 12;\n" +
746       "    String test = \"Test\";\n" +
747       "} finally {\n" +
748       "    int    z    = 12;\n" +
749       "    String zzzz = \"pnmhd\";\n" +
750       "}\n"
751     );
752   }
753
754   public void test_Align_ConsecutiveVars_InsideCodeBlock() {
755     getSettings().ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS = true;
756     doMethodTest(
757       "    System.out.println(\"AAAA\");\n" +
758       "    int a = 2;\n" +
759       "    \n" +
760       "    {\n" +
761       "      int x=2;\n" +
762       "      String name=3;\n" +
763       "    }\n",
764       "System.out.println(\"AAAA\");\n" +
765       "int a = 2;\n" +
766       "\n" +
767       "{\n" +
768       "    int    x    = 2;\n" +
769       "    String name = 3;\n" +
770       "}\n"
771     );
772   }
773   
774   public void test_AlignComments_BetweenChainedMethodCalls() {
775     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
776     doMethodTest(
777       "ActionBarPullToRefresh.from(getActivity())\n" +
778       "        // Mark the ListView as pullable\n" +
779       "        .theseChildrenArePullable(eventsListView)\n" +
780       "                // Set the OnRefreshListener\n" +
781       "        .listener(this)\n" +
782       "                // Use the AbsListView delegate for StickyListHeadersListView\n" +
783       "        .useViewDelegate(StickyListHeadersListView.class, new AbsListViewDelegate())\n" +
784       "                // Finally commit the setup to our PullToRefreshLayout\n" +
785       "        .setup(mPullToRefreshLayout);",
786       "ActionBarPullToRefresh.from(getActivity())\n" +
787       "                      // Mark the ListView as pullable\n" +
788       "                      .theseChildrenArePullable(eventsListView)\n" +
789       "                      // Set the OnRefreshListener\n" +
790       "                      .listener(this)\n" +
791       "                      // Use the AbsListView delegate for StickyListHeadersListView\n" +
792       "                      .useViewDelegate(StickyListHeadersListView.class, new AbsListViewDelegate())\n" +
793       "                      // Finally commit the setup to our PullToRefreshLayout\n" +
794       "                      .setup(mPullToRefreshLayout);"
795     );
796   }
797   
798   public void test_AlignComments_2() {
799     getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
800     doClassTest(
801       "public String returnWithBuilder2() {\n" +
802       "    return MoreObjects\n" +
803       "        .toStringHelper(this)\n" +
804       "        .add(\"value\", value)\n" +
805       "                   // comment\n" +
806       "        .toString();\n" +
807       "  }",
808       "public String returnWithBuilder2() {\n" +
809       "    return MoreObjects\n" +
810       "            .toStringHelper(this)\n" +
811       "            .add(\"value\", value)\n" +
812       "            // comment\n" +
813       "            .toString();\n" +
814       "}"
815     );
816   }
817   
818   public void test_AlignSubsequentOneLineMethods() {
819     getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
820     getSettings().ALIGN_SUBSEQUENT_SIMPLE_METHODS = true;
821     doTextTest(
822       "public class Test {\n" +
823       "\n" +
824       "    public void testSuperDuperFuckerMother() { System.out.println(\"AAA\"); }\n" +
825       "\n" +
826       "    public void testCounterMounter() { System.out.println(\"XXXX\"); }\n" +
827       "\n" +
828       "}",
829       "public class Test {\n" +
830       "\n" +
831       "    public void testSuperDuperFuckerMother() { System.out.println(\"AAA\"); }\n" +
832       "\n" +
833       "    public void testCounterMounter()         { System.out.println(\"XXXX\"); }\n" +
834       "\n" +
835       "}"
836     );
837   }
838 }