View Javadoc
1   /*
2   SuppressWarnings
3   format = .*un.*
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 InputSuppressWarningsSingle5
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          // violation below, 'The warning 'unforgiven' cannot be suppressed at this location'
33          @SuppressWarnings("unforgiven")
34          D;
35  
36          public static void foo() {
37  
38              // violation below, 'The warning 'unused' cannot be suppressed at this location'
39              @SuppressWarnings("unused")
40              Object o = new InputSuppressWarningsSingle5() {
41  
42                  @Override
43                  @SuppressWarnings("unchecked")
44                  // violation above, 'The warning 'unchecked' cannot be suppressed at this location'
45                  public String toString() {
46                      return "";
47                  }
48              };
49          }
50      }
51  
52      // violation below, 'The warning 'abcun' cannot be suppressed at this location'
53      @SuppressWarnings("abcun")
54      @Documented
55      @interface Sweet {
56          int cool();
57      }
58  
59      @Documented
60      @SuppressWarnings("abcun")
61      // violation above, 'The warning 'abcun' cannot be suppressed at this location'
62      @interface MoreSweetness {
63  
64          // violation below, 'The warning 'unused' cannot be suppressed at this location'
65          @SuppressWarnings("unused")
66          int cool();
67      }
68  
69      public class Junk {
70  
71          @SuppressWarnings("")
72          int a = 1;
73  
74          // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
75          @SuppressWarnings("unchecked")
76          @Deprecated
77          int b = 1;
78          void doFoo(String s, @SuppressWarnings("unchecked")String y) {
79              // violation above, 'The warning 'unchecked' cannot be suppressed at this location'
80  
81          }
82      }
83  
84      // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
85      @SuppressWarnings((false) ? "unchecked" : "")
86      class Cond {
87  
88          // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
89          @SuppressWarnings((false) ? "" : "unchecked")
90          public Cond() {
91  
92          }
93  
94          @SuppressWarnings((false) ? (true) ? "   " : "unused" : "unchecked") // 2 violations
95          public void aCond1() {
96  
97          }
98  
99          @SuppressWarnings((false) ? "unchecked" : (true) ? "   " : "unused") // 2 violations
100         public void aCond2() {
101 
102         }
103 
104         // violation below, 'The warning 'unchecked' cannot be suppressed at this location'
105         @java.lang.SuppressWarnings((false) ? "unchecked" :
106                 ("" == "") ? (false) ? (true) ? "" : "foo" : "    " : "unused")
107         // violation above, 'The warning 'unused' cannot be suppressed at this location'
108         public void seriously() {
109 
110         }
111     }
112 }