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 java.util.List;
13  
14  @Ann        // violation, "Annotation 'Ann' should be on the same line with its target."
15  @Ann2 interface TestInterface {
16  
17      @Ann    // violation, "Annotation 'Ann' should be on the same line with its target."
18      @Ann2 Integer getX();
19  }
20  
21  public @Ann     // violation, "Annotation 'Ann' should be on the same line with its target."
22                  // violation below, "Annotation 'Ann' should be on the same line with its target."
23  @Ann2 class InputAnnotationOnSameLineCheckInterfaceAndEnum implements @Ann
24          @Ann2 TestInterface {
25  
26      @Ann        // violation, "Annotation 'Ann' should be on the same line with its target."
27      @Ann2 private Integer x = new @Ann // violation, should be on the same line with its target."
28              @Ann2 Integer(0);
29  
30              // violation below, "Annotation 'Ann' should be on the same line with its target."
31      private List<@Ann
32              @Ann2 Integer> integerList;
33  
34      @Ann        // violation, "Annotation 'Ann' should be on the same line with its target."
35      @Ann2 enum TestEnum {
36          A1, A2
37      }
38  
39      @Ann        // violation, "Annotation 'Ann' should be on the same line with its target."
40  
41      @Ann2 public InputAnnotationOnSameLineCheckInterfaceAndEnum() {}
42  
43      @Ann        // violation, "Annotation 'Ann' should be on the same line with its target."
44                  // violation below, "Annotation 'Ann' should be on the same line with its target."
45      @Ann2 public void setX(@Ann
46  
47              @Ann2 int x) throws @Ann // violation, should be on the same line with its target."
48                      @Ann2 Exception {
49  
50          this.<@Ann // violation, "Annotation 'Ann' should be on the same line with its target."
51                  @Ann2 Integer> getXAs();
52          this.x = x;
53      }
54  
55      @Override public Integer getX() {
56          return (@Ann // violation, "Annotation 'Ann' should be on the same line with its target."
57                  @Ann2 Integer) x;
58      }
59  
60      public <T> T getXAs() {
61          return (T) x;
62      }
63  }
64  
65  @Ann        // violation, "Annotation 'Ann' should be on the same line with its target."
66  @Ann2 @interface TestAnnotation {
67  
68      @Ann    // violation, "Annotation 'Ann' should be on the same line with its target."
69      @Ann2 int x();
70  }