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