View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.blocks.rightcurly;
2   
3   public class InputRightCurlyAloneOrSingleline {
4   
5       public boolean equals(Object other) { boolean flag = true; return flag; }
6   
7       public int hashCode()
8       { 
9           int a = 10;
10          return 1;
11      }
12  
13      private void foo()
14      { int var1 = 5; var2 = 6; } 
15  
16      private void foo1() { return; } 
17  
18      private String foo2() { return toString();
19      } 
20  
21      private void foo3() { ; return; } 
22  
23      private int var1;
24      private int var2;
25      public InputRightCurlyAloneOrSingleline() { this.var1 = 1; } 
26      public InputRightCurlyAloneOrSingleline(int var1, int var2) { this.var1 = var1; this.var2 = var2; } 
27  
28      private void foo4() { ;; } 
29  
30      private void foo5() { ; } 
31  
32      private void foo6() {  } 
33  
34      private void foo12() {
35          try { int i = 5; int b = 10; } 
36          catch (Exception e) { } 
37      } 
38  
39      private void foo13() {
40          for (int i = 0; i < 10; i++) { int a = 5; int b = 6; } 
41  
42          do
43          {
44              var1 = 2;
45          } 
46          while (var2 == 2);
47      } 
48  
49      static { int a; int b; } 
50  
51      { int c; int d;} 
52  
53      private void foo14() {
54          if (var1 > 0) {
55              return;
56          } 
57      } 
58  
59      private void foo15() {
60          class A { int a; } var1++; //violation
61          class B {  } 
62          if(true) {
63  
64          } 
65          else;
66      }
67  
68      private void foo16() {
69          if (true) { return; } else { } //violation
70          if (false) {
71          }
72      }
73  
74      private void foo17() { int var1 = 5; var2 = 6; } private void foo18() {int var1 = 5; var2 = 6; } //violation
75  
76      private void foo19() {int var1 = 5;
77          var2 = 6;} //violation
78  
79      private String foo20() {
80          do { var2 ++; }  
81          while (var2 < 15);
82  
83          while (var1 < 10) { var1++; } 
84  
85          do { var2++; var1++; } while (var2 < 15); return ""+0xCAFEBABE; //violation
86      }
87  
88      private void foo21() {
89          new Object() { @Override protected void finalize() { "".toString(); }}; 
90      } 
91  
92      void foo22() {
93          long startTime = System.nanoTime();
94          try {
95              int a = 5;
96              toString();
97          } catch (Exception e) { //violation
98              throw new RuntimeException(e);
99          } finally { toString(); } //violation
100     }
101 
102     void doDoubleBraceInitialization() {
103         java.util.Map<String, String> map = new java.util.LinkedHashMap<String, String>() {{
104             put("Hello", "World");
105             put("first", "second");
106             put("polygene", "lubricants");
107             put("alpha", "betical");
108         }}; // it's ok
109 
110         Thread t = new Thread() {@Override public void run() {super.run();}};
111         new Object() { @Override protected void finalize() { "".toString(); }  { int a = 5; }};
112         new Object() { @Override protected void finalize() { "".toString(); }  int b = 10; };
113         new Object() { @Override protected void finalize() { "".toString(); }  { int c = 5; } int d = 8; };
114 
115         java.util.Map<String, String> map2 = new java.util.LinkedHashMap<String, String>() {{
116             put("Hello", "World");
117             put("first", "second");
118             put("polygene", "lubricants");
119             put("alpha", "betical");}  //violation
120         };
121 
122         java.util.Map<String, String> map3 = new java.util.LinkedHashMap<String, String>() {{
123             put("Hello", "World");
124             put("first", "second");
125             put("polygene", "lubricants");
126             put("alpha", "betical");}}; //violation
127 
128         java.util.Map<String, String> map4 = new java.util.LinkedHashMap<String, String>() {{
129             put("Hello", "World");
130             put("first", "second");
131             put("polygene", "lubricants");
132             put("alpha", "betical");
133         }
134         };
135 
136         foo23(new java.util.HashSet<String>() {{
137             add("XZ13s");
138             add("AB21/X");
139             add("YYLEX");
140             add("AR5E");
141         }});  //it's ok, can't be formatted better
142 
143         foo23(new java.util.HashSet<String>() {{
144             add("XZ13s");
145             add("AB21/X");
146             add("YYLEX");
147             add("AR5E");
148         }});} //violation
149 
150 
151     void foo23(java.util.HashSet<String> set) {
152     }
153 
154     void foo25() {
155         for (int i = 0; i < 10; i++) {
156             System.identityHashCode("Hello, world!");
157         }} //violation
158 
159     void foo26() {
160         for (int i = 0; i < 10; i++) {
161             System.identityHashCode("Hello, world!");}} //violation
162 
163     void foo27() {
164         for (int i = 0; i < 10; i++) {for (int j = 0; j < 15; j++) {int a;}}} //violation
165 
166     private java.util.ArrayList<Integer> foo28(int delta) {
167         return new java.util.ArrayList<Integer>() {
168             @Override public int size() { return Math.max(0, super.size() + 1);};
169         };
170     }
171 
172     private void foo29() {
173         boolean flag = true;
174         if (flag) {
175             System.identityHashCode("heh");
176             flag = !flag; } String.CASE_INSENSITIVE_ORDER. //violation
177             equals("Xe-xe");
178     }
179 
180     void foo30() {
181         if (true) {
182             getClass();} // violation
183 
184         for (int i = 0; i == 0; i++) {
185             getClass();} // violation
186 
187         while (true) {
188             getClass();} // violation
189     }
190 }