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