View Javadoc
1   /*
2   FinalParameters
3   ignorePrimitiveTypes = (default)false
4   tokens = LITERAL_CATCH
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.finalparameters;
10  
11  import java.awt.event.ActionEvent;
12  
13  import javax.swing.AbstractAction;
14  import javax.swing.Action;
15  
16  /**
17   * Test case for detecting missing final parameters.
18   * @author Lars Kühne
19   **/
20  class InputFinalParameters4
21  {
22      /** no param constructor */
23      InputFinalParameters4()
24      {
25      }
26  
27      /** non final param constructor */
28      InputFinalParameters4(String s)
29      {
30      }
31  
32      /** non final param constructor */
33      InputFinalParameters4(final Integer i)
34      {
35      }
36  
37      /** final param constructor with annotation */
38      InputFinalParameters4(final @MyAnnotation33 Class<Object> i)
39      {
40      }
41  
42      /** non-final param constructor with annotation*/
43      InputFinalParameters4(@MyAnnotation33 Boolean i)
44      {
45      }
46  
47      /** mixed */
48      InputFinalParameters4(String s, final Integer i)
49      {
50      }
51  
52      /** no param method */
53      void method()
54      {
55      }
56  
57      /** non final param method */
58      void method(String s)
59      {
60      }
61  
62      /** final param method */
63      void method(final Integer i)
64      {
65      }
66  
67      /** final param method with annotation **/
68      void method(@MyAnnotation33 final Object s)
69      {
70  
71      }
72  
73      /** non-final param method with annotation **/
74      void method(@MyAnnotation33 Class<Object> s)
75      {
76  
77      }
78  
79      /** mixed */
80      void method(String s, final Integer i)
81      {
82      }
83  
84      /** interface methods should not be flagged. */
85      interface TestInterface
86      {
87          void method(String s);
88      }
89  
90      /** methods in anonymous inner classes */
91      void holder()
92      {
93          Action a = new AbstractAction()
94              {
95                  public void actionPerformed(ActionEvent e)
96                  {
97                  }
98                  void somethingElse(@MyAnnotation33 ActionEvent e)
99                  {
100                 }
101             };
102 
103         Action b = new AbstractAction()
104             {
105                 public void actionPerformed(final ActionEvent e)
106                 {
107                 }
108                 void somethingElse(@MyAnnotation33 final ActionEvent e)
109                 {
110                 }
111             };
112     }
113 
114     /** methods with complicated types of the parameters. */
115     void methodA(String aParam) {
116     }
117 
118     void methodB(String[] args) {
119     }
120 
121     void methodC(String[] args) {
122     }
123 
124     /** some catch blocks */
125     void method1()
126     {
127         try {
128             String.CASE_INSENSITIVE_ORDER.equals("");
129         }
130         catch (NullPointerException npe) { // violation
131             npe.getMessage();
132         }
133         catch (@MyAnnotation33 final ClassCastException e) {
134             e.getMessage();
135         }
136         catch (RuntimeException e) { // violation
137             e.getMessage();
138         }
139         catch (@MyAnnotation33 NoClassDefFoundError e) { // violation
140             e.getMessage();
141         }
142     }
143 
144     native void method(int i);
145 }
146 
147 abstract class AbstractClass4
148 {
149     public abstract void abstractMethod(int aParam);
150 }
151 
152 class Foo4
153 {
154     /* Some for-each clauses */
155     public void Bar()
156     {
157         for(String s : someExpression())
158         {
159 
160         }
161         for(final String s : someExpression())
162         {
163 
164         }
165         for(@MyAnnotation33 String s : someExpression())
166         {
167 
168         }
169         for(@MyAnnotation33 final String s : someExpression())
170         {
171 
172         }
173     }
174 
175     private String[] someExpression()
176     {
177         return null;
178     }
179 }
180 
181 @interface MyAnnotation34 {
182 }