View Javadoc
1   /*
2   AnnotationOnSameLine
3   tokens = CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, \
4            VARIABLE_DEF, PARAMETER_DEF, ANNOTATION_DEF, TYPECAST, LITERAL_THROWS, \
5            IMPLEMENTS_CLAUSE, TYPE_ARGUMENT, LITERAL_NEW, DOT, ANNOTATION_FIELD_DEF
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.annotation.annotationonsameline;
11  
12  import static java.lang.annotation.ElementType.TYPE_USE;
13  
14  import java.lang.annotation.Target;
15  import java.util.List;
16  
17  public class InputAnnotationOnSameLine {
18      // violation below, "Annotation 'Ann' should be on the same line with its target."
19      @Ann public
20      @Ann2 class E {}
21  
22      // violation below, "Annotation 'Ann' should be on the same line with its target."
23      @Ann private
24      @Ann2 class A {}
25      public void wildcardCase() {
26          List<@Ann ?> list;
27      }
28  
29      public String typeCastCase() {
30          Object s = new String();
31          return (@Ann String) s;
32      }
33  
34      public void wildcardCase1() {
35          // violation below, 'Annotation 'Ann' should be on the same line with its target.'
36          List<@Ann
37                  ?> list;
38      }
39  
40      // 2 violations 3 lines below:
41      //    "Annotation 'Deprecated' should be on the same line with its target."
42      //    "Annotation 'SuppressWarnings' should be on the same line with its target."
43      @Deprecated @SuppressWarnings("unchecked")
44      public void proceed(int parameter1,  int parameter2,  int parameter3,
45                          int parameter4,  int parameter5) { }
46  
47      @Deprecated @SuppressWarnings("unchecked") public void proceedGood(int parameter1,
48                                                        int parameter2, int parameter3,
49                                                        int parameter4,  int parameter5) { }
50  
51      int[][][] i = new @Ann3(integer = 1) int[0][][];
52  
53      @Target({TYPE_USE}) @interface Ann {}
54      @Target({TYPE_USE}) @interface Ann2 {}
55      @Target({TYPE_USE}) @interface Ann3 { int integer();}
56  
57  }