View Javadoc
1   /*
2   SuppressWarnings
3   format = ^unchecked$*|^unused$
4   tokens = (default)CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, \
5            ENUM_CONSTANT_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, CTOR_DEF, \
6            COMPACT_CTOR_DEF, RECORD_DEF
7   
8   
9   */
10  
11  package com.puppycrawl.tools.checkstyle.checks.annotation.suppresswarnings;
12  
13  import java.lang.annotation.Documented;
14  
15  // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
16  @SuppressWarnings("unchecked")
17  public class InputSuppressWarningsSingle6
18  {
19      @SuppressWarnings("   ")
20      class Empty {
21  
22          @SuppressWarnings("")
23          public Empty() {
24  
25          }
26      }
27  
28      // violation below, 'The warning 'unused' cannot be suppressed at this location'
29      @SuppressWarnings("unused")
30      enum Duh {
31  
32          @SuppressWarnings("unforgiven")
33          D;
34  
35          public static void foo() {
36  
37              // violation below, 'The warning 'unused' cannot be suppressed at this location'
38              @SuppressWarnings("unused")
39              Object o = new InputSuppressWarningsSingle6() {
40  
41                  @Override
42                  @SuppressWarnings("unchecked")
43                  // violation above, 'The warning 'unchecked' cannot be suppressed at this location'
44                  public String toString() {
45                      return "";
46                  }
47              };
48          }
49      }
50  
51      @SuppressWarnings("abcun")
52      @Documented
53      @interface Sweet {
54          int cool();
55      }
56  
57      @Documented
58      @SuppressWarnings("abcun")
59      @interface MoreSweetness {
60  
61          // violation below, 'The warning 'unused' cannot be suppressed at this location'
62          @SuppressWarnings("unused")
63          int cool();
64      }
65  
66      public class Junk {
67  
68          @SuppressWarnings("")
69          int a = 1;
70  
71          // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
72          @SuppressWarnings("unchecked")
73          @Deprecated
74          int b = 1;
75          void doFoo(String s, @SuppressWarnings("unchecked")String y) {
76              // violation above, 'The warning 'unchecked' cannot be suppressed at this location'
77  
78          }
79      }
80  
81      // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
82      @SuppressWarnings((false) ? "unchecked" : "")
83      class Cond {
84  
85          // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
86          @SuppressWarnings((false) ? "" : "unchecked")
87          public Cond() {
88  
89          }
90  
91          @SuppressWarnings((false) ? (true) ? "   " : "unused" : "unchecked") // 2 violations
92          public void aCond1() {
93  
94          }
95  
96          @SuppressWarnings((false) ? "unchecked" : (true) ? "   " : "unused") // 2 violations
97          public void aCond2() {
98  
99          }
100 
101         // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
102         @java.lang.SuppressWarnings((false) ? "unchecked" :
103                 ("" == "") ? (false) ? (true) ? "" : "foo" : "    " : "unused")
104         // violation above, 'The warning 'unused' cannot be suppressed at this location'
105         public void seriously() {
106 
107         }
108     }
109 }