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