View Javadoc
1   /*
2   RightCurly
3   option = ALONE
4   tokens = CLASS_DEF, METHOD_DEF, LITERAL_IF, LITERAL_ELSE, LITERAL_DO, LITERAL_WHILE, \
5            LITERAL_FOR, STATIC_INIT, INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
11  
12  public class InputRightCurlyTestOptionAlone {
13  
14      private int a;
15      private static int b;
16      {  a = 2; } // violation ''}' at column 15 should be alone on a line'
17      static { b = 3; } // violation ''}' at column 21 should be alone on a line'
18  
19      void method1() {
20          Thread t = new Thread() {@Override public void run() {
21              int a; int b;} // violation ''}' at column 26 should be alone on a line'
22          };
23      }
24  
25      void method2(java.util.HashSet<String> set) {
26          java.util.Map<String, String> map1 = new java.util.LinkedHashMap<String, String>() {{
27              put("Hello", "World");
28              put("first", "second");
29              put("polygene", "lubricants");
30              put("alpha", "betical");} // violation ''}' at column 37 should be alone on a line'
31          };
32  
33          java.util.Map<String, String> map2 = new java.util.LinkedHashMap<String, String>() {{
34              put("Hello", "World");
35              put("first", "second");
36              put("polygene", "lubricants");
37              put("alpha", "betical");
38          }};
39      }
40  
41      void method3() {
42          method2(new java.util.HashSet<String>() {{
43              add("XZ13s");
44              add("AB21/X");
45              add("YYLEX");
46              add("AR5E");
47          }}); // violation ''}' at column 9 should be alone on a line'
48      }
49  
50      int method4(int a) {
51          if (a>2) a*=10; return ++a; } // violation ''}' at column 37 should be alone on a line'
52  
53      void method5(int a) {
54          while (a > 5) { a--; } // violation ''}' at column 30 should be alone on a line'
55  
56          if (a > 4) { a++; } // violation ''}' at column 27 should be alone on a line'
57  
58          do {a--;} while (a > 3); // violation ''}' at column 17 should be alone on a line'
59          // violation below ''}' at column 53 should be alone on a line'
60          for (int i = 1; i < 10; i++) { byte b = 10; }
61  
62          if (a < 2) { --a; } else if (a > 3) { a++; } // 2 violations
63  
64          java.util.List<String> list = new java.util.ArrayList<>();
65          list.stream()
66                  .filter(e -> {return !e.isEmpty() && !"null".equals(e);} )
67                  .collect(java.util.stream.Collectors.toList());
68      }
69  
70      void method6(int a) {
71          java.util.Map<String, String> map3 = new java.util.LinkedHashMap<String, String>() {{
72              put("Hello", "World");
73              put("first", "second");
74              put("polygene", "lubricants");
75          }{}; // 2 violations
76          };
77      }
78  
79      public @interface TestAnnotation {} // violation ''}' at column 39 should be alone on a line'
80      // violation below ''}' at column 56 should be alone on a line'
81      public @interface TestAnnotation1{ String value(); }
82  
83      public @interface TestAnnotation2 {
84          String value();} // violation ''}' at column 24 should be alone on a line'
85  
86      public @interface TestAnnotation3 {
87          String value();
88      }
89  
90      public @interface TestAnnottation4 { String value();
91      }
92  
93      interface Interface1
94      {
95          int i = 1;
96          public void meth1(); } // violation ''}' at column 30 should be alone on a line'
97  
98      interface Interface2
99      { int i = 1; public void meth1(); } // violation ''}' at column 39 should be alone on a line'
100 
101     interface Interface3 {
102         void display();
103         interface Interface4 {
104             void myMethod();
105         }} // 2 violations
106 }