1   package com.puppycrawl.tools.checkstyle.checks.javadoc.missingjavadoctype;
2   import java.io.IOException;
3   // Tests for Javadoc tags.
4   class InputMissingJavadocTypeTags1 // warn
5   {
6       // Invalid - should be Javadoc
7       private int mMissingJavadoc;
8   
9       // Invalid - should be Javadoc
10      void method1()
11      {
12      }
13  
14      /** @param unused asd **/
15      void method2()
16      {
17      }
18  
19      /** missing return **/
20      int method3()
21      {
22          return 3;
23      }
24  
25      /**
26       * <p>missing return
27       * @param aOne ignored
28       **/
29      int method4(int aOne)
30      {
31          return aOne;
32      }
33  
34      /** missing throws **/
35      void method5()
36          throws Exception
37      {
38      }
39  
40      /**
41       * @see missing throws
42       * @see need to see tags to avoid shortcut logic
43       **/
44      void method6()
45          throws Exception
46      {
47      }
48  
49      /** @throws WrongException error **/
50      void method7()
51          throws Exception, NullPointerException
52      {
53      }
54  
55      /** missing param **/
56      void method8(int aOne)
57      {
58      }
59  
60      /**
61       * @see missing param
62       * @see need to see tags to avoid shortcut logic
63       **/
64      void method9(int aOne)
65      {
66      }
67  
68      /** @param WrongParam error **/
69      void method10(int aOne, int aTwo)
70      {
71      }
72  
73      /**
74       * @param Unneeded parameter
75       * @return also unneeded
76       **/
77      void method11()
78      {
79      }
80  
81      /**
82       * @return first one
83       * @return duplicate
84       **/
85      int method12()
86      {
87          return 0;
88      }
89  
90      /**
91       * @param aOne
92       * @param aTwo
93       *
94       *     This is a multiline piece of javadoc
95       *     Unlike the previous one, it actually has content
96       * @param aThree
97       *
98       *
99       *     This also has content
100      * @param aFour
101 
102      *
103      * @param aFive
104      **/
105     void method13(int aOne, int aTwo, int aThree, int aFour, int aFive)
106     {
107     }
108 
109     /** @param aOne Perfectly legal **/
110     void method14(int aOne)
111     {
112     }
113 
114     /** @throws java.io.IOException
115      *               just to see if this is also legal **/
116     void method14()
117        throws java.io.IOException
118     {
119     }
120 
121 
122 
123     // Test static initialiser
124     static
125     {
126         int x = 1; // should not require any javadoc
127     }
128 
129     // test initialiser
130     {
131         int z = 2; // should not require any javadoc
132     }
133 
134     /** handle where variable declaration over several lines **/
135     private static final int
136         ON_SECOND_LINE = 2;
137 
138 
139     /**
140      * Documenting different causes for the same exception
141      * in separate tags is OK (bug 540384).
142      *
143      * @throws java.io.IOException if A happens
144      * @throws java.io.IOException if B happens
145      **/
146     void method15()
147        throws java.io.IOException
148     {
149     }
150 
151     /** {@inheritDoc} **/
152     public String toString()
153     {
154         return super.toString();
155     }
156 
157     /** getting code coverage up **/
158     static final int serialVersionUID = 666;
159 
160     //**********************************************************************/
161     // Method Name: method16
162     /**
163      * handle the case of an elaborate header surrounding javadoc comments
164      *
165      * @param aOne valid parameter content
166      */
167     //**********************************************************************/
168     void method16(int aOne)
169     {
170     }
171 
172 
173     /**
174      * @throws ThreadDeath although bad practice, should be silently ignored
175      * @throws ArrayStoreException another r/t subclass
176      * @throws IllegalMonitorStateException should be told to remove from throws
177      */
178     void method17()
179         throws IllegalMonitorStateException
180     {
181     }
182 
183     /**
184      * declaring the imported version of an Exception and documenting
185      * the full class name is OK (bug 658805).
186      * @throws java.io.IOException if bad things happen.
187      */
188     void method18()
189         throws IOException
190     {
191         throw new IOException("to make compiler happy");
192     }
193 
194     /**
195      * reverse of bug 658805.
196      * @throws IOException if bad things happen.
197      */
198     void method19()
199         throws java.io.IOException
200     {
201         throw new IOException("to make compiler happy");
202     }
203 
204     /**
205      * Bug 579190, "expected return tag when one is there".
206      *
207      * Linebreaks after return tag should be legal.
208      *
209      * @return
210      *   the bug that states that linebreak should be legal
211      */
212     int method20()
213     {
214         return 579190;
215     }
216 
217     /**
218      * Bug XXXX, "two tags for the same exception"
219      *
220      * @exception java.io.IOException for some reasons
221      * @exception IOException for another reason
222      */
223     void method21()
224        throws IOException
225     {
226     }
227 
228     /**
229      * RFE 540383, "Unused throws tag for exception subclass"
230      *
231      * @exception IOException for some reasons
232      * @exception java.io.FileNotFoundException for another reasons
233      */
234     void method22()
235        throws IOException
236     {
237     }
238 
239     /**
240      * @exception WrongException exception w/o class info but matched by name
241      */
242     void method23() throws WrongException
243     {
244     }
245 
246     /**
247      * Bug 803577, "allowThrowsTagsForSubclasses/allowMissingThrowsTag interfere"
248      *
249      * no exception tag for IOException, but here is a tag for its subclass.
250      * @exception java.io.FileNotFoundException for another reasons
251      */
252     void method24() throws IOException
253     {
254     }
255 
256     /**
257      * Bug 841942, "ArrayIndexOutOfBounds in JavadocStyle".
258      * @param aParam there is no such param in the method.
259      * The problem should be reported with correct line number.
260      */
261 
262     void method25()
263     {
264     }
265 
266     /** {@inheritDoc} */
267     int method26()
268     { return 0;
269     }
270 
271     /**
272      * {@inheritDoc}
273      * @return something very important.
274      */
275     int method27(int aParam)
276     { return 0;
277     }
278 
279     /**
280      * @return something very important.
281      * {@inheritDoc}
282      */
283     int method28(int aParam)
284     { return 0;
285     }
286 
287     /**
288      * {@inheritDoc}
289      *
290      * @return 1
291      */
292     public int foo(Object _arg) {
293 
294         return 1;
295     }
296 }
297 
298 enum InputJavadocTypeTagsEnum // warn
299 {
300     CONSTANT_A,
301 
302     /**
303      *
304      */
305     CONSTANT_B,
306 
307     CONSTANT_C
308     {
309         /**
310          *
311          */
312         public void someMethod()
313         {
314         }
315 
316         public void someOtherMethod()
317         {
318 
319         }
320     }
321 }
322 
323 @interface InputJavadocTypeTagsAnnotation // warn
324 {
325     String someField();
326     int A_CONSTANT = 0;
327     /** Some javadoc. */
328     int B_CONSTANT = 1;
329     /** @return This tag is valid here and expected with Java 8 */
330     String someField2();
331 }
332 
333 /**
334  * Some javadoc.
335  */
336 public class InputMissingJavadocTypeTags {
337 
338     /**
339      * Constructor.
340      */
341     public InputMissingJavadocTypeTags() {
342     }
343 
344    /**
345     * Sample method.
346     * @param arg1   first argument
347     * @param arg2   second argument
348     * @return java.lang.String      the result string
349     * @throws java.lang.Exception   in case of problem
350     */
351     public final String myMethod(final String arg1,
352                                  final Object arg2)
353       throws Exception
354     {
355         return null;
356     }
357 }
358 
359 /**
360  *  Added to make this file compilable.
361  */
362 class WrongException extends RuntimeException
363 {
364 }