View Javadoc
1   package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace;
2   
3   import java.io.IOException;
4   import java.io.StringWriter;
5   import java.io.Writer;
6   
7   public class InputParenPad
8   {
9       class ParenPadNoSpace  {
10          ParenPadNoSpace() {
11              this(0);
12          }
13  
14          ParenPadNoSpace(int i) {
15              super();
16          }
17  
18          @SuppressWarnings("")
19          void method(boolean status) {
20              try (Writer writer = new StringWriter()) {
21                  do {
22                      writer.append("a");
23                  } while (status);
24              } catch (IOException e) {
25                  while (status) {
26                      for (int i = 0; i < (long) (2 * (4 / 2)); i++) {
27                          if (i > 2) {
28                              synchronized (this) {
29                                  switch (i) {
30                                      case 3:
31                                      case (4):
32                                      case 5:
33                                          break;
34                                  }
35                              }
36                          }
37                      }
38                  }
39              }
40          }
41      }
42  
43      class ParenPadSpaceLeft {
44          ParenPadSpaceLeft( ) { // warning
45              this( 0); // warning
46          }
47  
48          ParenPadSpaceLeft( int i) { // warning
49              super( ); // warning
50          }
51  
52          @SuppressWarnings( "") // warning
53          void method( boolean status) { // warning
54              try ( Writer writer = new StringWriter( )) { // warning
55                  do {
56                      writer.append("a");
57                  } while ( status); // warning
58              } catch ( IOException e) { // warning
59                  while ( status) { // warning
60                      for ( int i = 0; i < ( long) ( 2 * ( 4 / 2)); i++) { // warning
61                          if ( i > 2) { // warning
62                              synchronized ( this) { // warning
63                                  switch ( i) { // warning
64                                      case 3:
65                                      case ( 4): // warning
66                                      case 5:
67                                          break;
68                                  }
69                              }
70                          }
71                      }
72                  }
73              }
74          }
75      }
76  
77      class ParenPadSpaceRight {
78          ParenPadSpaceRight( ) { // warning
79              this(0 ); // warning
80          }
81  
82          ParenPadSpaceRight(int i ) { // warning
83              super( ); // warning
84          }
85  
86          @SuppressWarnings("" ) // warning
87          void method(boolean status ) { // warning
88              try (Writer writer = new StringWriter( ) ) { // warning
89                  do {
90                      writer.append("a" ); // warning
91                  } while (status ); // warning
92              } catch (IOException e ) { // warning
93                  while (status ) { // warning
94                      for (int i = 0; i < (long ) (2 * (4 / 2 ) ); i++ ) { // warning
95                          if (i > 2 ) { // warning
96                              synchronized (this ) { // warning
97                                  switch (i ) { // warning
98                                      case 3:
99                                      case (4 ): // warning
100                                     case 5:
101                                         break;
102                                 }
103                             }
104                         }
105                     }
106                 }
107             }
108         }
109     }
110 
111     String foo() {
112         return ( (Object // warning
113                 ) bar( ( 1 > 2 ) ? // warning
114                         ( ( 3 < 4 )? false : true ) : // warning
115                         ( ( 1 == 1 ) ? false : true) ) ).toString(); // warning
116     }
117     @MyAnnotation
118     public boolean bar(boolean a) {
119         assert ( true ); // warning
120         return true;
121     }
122 
123     boolean fooo = this.bar(( true && false ) && true); // warning
124 }
125 @interface MyAnnotation {
126     String someField( ) default "Hello world"; // warning
127 }
128 
129 enum MyEnum {
130     SOME_CONSTANT( ) { // warning
131         int i = (int) (2 * (4 / 2)
132                 );
133     };
134 
135     public void myMethod() {
136         String s = "test";
137         Object o = s;
138         ((String)o).length();
139         ( (String)o ).length(); // warning
140     }
141 
142     public void crisRon() {
143         Object leo = "messi";
144         Object ibra = leo;
145         ((String)leo).compareTo( (String)ibra ); // warning
146         Math.random();
147     }
148 
149     public void intStringConv() {
150         Object a = 5;
151         Object b = "string";
152         int w = Integer.parseInt((String)a);
153         int x = Integer.parseInt( (String)a); // warning
154         double y = Double.parseDouble((String)a ); // warning
155         float z = Float.parseFloat( (String)a ); // warning
156         String d = ((String)b);
157     }
158 
159     public int something( Object o ) { // warning
160         if ( o == null || !( o instanceof Float ) ) { // warning
161             return -1;
162         }
163         return Integer.valueOf( 22 ).compareTo( (Integer) o ); // warning
164     }
165 
166     private void launch(Integer number ) { // warning
167         String myInt = ( number.toString() + '\0' ); // warning
168         boolean result = false;
169         if (number == 123)
170             result = true;
171     }
172 
173     private static String getterName( Exception t) { // warning
174         if (t instanceof ClassNotFoundException ) { // warning
175             return ( (ClassNotFoundException) t ).getMessage(); // warning
176         }
177         else {
178             return "?";
179         }
180     }
181 
182     private Object exam;
183 
184     public String testing() {
185         return ( this.exam != null ) // warning
186                 ? ( ( Enum )this.exam ).name() // warning
187                 : null;
188     }
189 
190     Object stringReturnValue( Object result ) { // warning
191         if ( result instanceof String ) { // warning
192             result = ( (String) result ).length(); // warning
193         }
194         return result;
195     }
196 
197 
198 
199     private void except() {
200         java.util.ArrayList<Integer> arrlist = new java.util.ArrayList<Integer>( 5 ); // warning
201         arrlist.add( 20); // warning
202         arrlist.add(15 ); // warning
203         arrlist.add( 30 ); // warning
204         arrlist.add(45);
205         try {
206             ( arrlist ).remove( 2); // warning
207         } catch ( IndexOutOfBoundsException x ) { // warning
208             x.getMessage();
209         }
210         org.junit.Assert.assertThat( "123", org.hamcrest.CoreMatchers.is( "123" ) ); // warning
211         org.junit.Assert.assertThat( "Help! Integers don't work", // warning
212                 0, org.hamcrest.CoreMatchers.is( 1 ) ); // warning
213     }
214 
215     private void tryWithResources() throws Exception {
216         try (AutoCloseable a = null) {} // ok
217         try (AutoCloseable a = null; AutoCloseable b = null) {} // ok
218         try (AutoCloseable a = null; AutoCloseable b = null; ) {} // ok
219         try (AutoCloseable a = null; AutoCloseable b = null; ) {} // ok
220         try (AutoCloseable a = null ) {} // warning
221         try (AutoCloseable a = null; AutoCloseable b = null ) {} // warning
222     }
223 }