author | jlahoda |
Mon, 21 Oct 2019 15:38:26 +0200 | |
changeset 58713 | ad69fd32778e |
parent 55263 | 830ca7b43b95 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43588
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
2 |
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
41637 | 28 |
import java.util.Arrays; |
10 | 29 |
import java.util.EnumSet; |
30 |
import java.util.Map; |
|
22163 | 31 |
import java.util.concurrent.ConcurrentHashMap; |
32 |
||
10 | 33 |
import com.sun.tools.javac.code.Symbol.*; |
41637 | 34 |
import com.sun.tools.javac.main.Option; |
10 | 35 |
import com.sun.tools.javac.util.Context; |
36 |
import com.sun.tools.javac.util.List; |
|
37 |
import com.sun.tools.javac.util.Options; |
|
38 |
import com.sun.tools.javac.util.Pair; |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14369
diff
changeset
|
39 |
|
10 | 40 |
/** |
41 |
* A class for handling -Xlint suboptions and @SuppresssWarnings. |
|
42 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
43 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
44 |
* If you write code that depends on this, you do so at your own risk. |
10 | 45 |
* This code and its internal interfaces are subject to change or |
46 |
* deletion without notice.</b> |
|
47 |
*/ |
|
48 |
public class Lint |
|
49 |
{ |
|
50 |
/** The context key for the root Lint object. */ |
|
22163 | 51 |
protected static final Context.Key<Lint> lintKey = new Context.Key<>(); |
10 | 52 |
|
53 |
/** Get the root Lint instance. */ |
|
54 |
public static Lint instance(Context context) { |
|
55 |
Lint instance = context.get(lintKey); |
|
56 |
if (instance == null) |
|
57 |
instance = new Lint(context); |
|
58 |
return instance; |
|
59 |
} |
|
60 |
||
61 |
/** |
|
62 |
* Returns the result of combining the values in this object with |
|
63 |
* the given annotation. |
|
64 |
*/ |
|
65 |
public Lint augment(Attribute.Compound attr) { |
|
66 |
return augmentor.augment(this, attr); |
|
67 |
} |
|
68 |
||
69 |
||
70 |
/** |
|
71 |
* Returns the result of combining the values in this object with |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
16301
diff
changeset
|
72 |
* the metadata on the given symbol. |
10 | 73 |
*/ |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
16301
diff
changeset
|
74 |
public Lint augment(Symbol sym) { |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
16301
diff
changeset
|
75 |
Lint l = augmentor.augment(this, sym.getDeclarationAttributes()); |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
16301
diff
changeset
|
76 |
if (sym.isDeprecated()) { |
10 | 77 |
if (l == this) |
78 |
l = new Lint(this); |
|
79 |
l.values.remove(LintCategory.DEPRECATION); |
|
80 |
l.suppressedValues.add(LintCategory.DEPRECATION); |
|
81 |
} |
|
82 |
return l; |
|
83 |
} |
|
84 |
||
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
25874
diff
changeset
|
85 |
/** |
41637 | 86 |
* Returns a new Lint that has the given LintCategorys suppressed. |
87 |
* @param lc one or more categories to be suppressed |
|
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
25874
diff
changeset
|
88 |
*/ |
41637 | 89 |
public Lint suppress(LintCategory... lc) { |
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
25874
diff
changeset
|
90 |
Lint l = new Lint(this); |
41637 | 91 |
l.values.removeAll(Arrays.asList(lc)); |
92 |
l.suppressedValues.addAll(Arrays.asList(lc)); |
|
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
25874
diff
changeset
|
93 |
return l; |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
25874
diff
changeset
|
94 |
} |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
25874
diff
changeset
|
95 |
|
10 | 96 |
private final AugmentVisitor augmentor; |
97 |
||
98 |
private final EnumSet<LintCategory> values; |
|
99 |
private final EnumSet<LintCategory> suppressedValues; |
|
100 |
||
22163 | 101 |
private static final Map<String, LintCategory> map = new ConcurrentHashMap<>(20); |
10 | 102 |
|
103 |
protected Lint(Context context) { |
|
104 |
// initialize values according to the lint options |
|
105 |
Options options = Options.instance(context); |
|
41637 | 106 |
|
107 |
if (options.isSet(Option.XLINT) || options.isSet(Option.XLINT_CUSTOM, "all")) { |
|
108 |
// If -Xlint or -Xlint:all is given, enable all categories by default |
|
109 |
values = EnumSet.allOf(LintCategory.class); |
|
110 |
} else if (options.isSet(Option.XLINT_CUSTOM, "none")) { |
|
111 |
// if -Xlint:none is given, disable all categories by default |
|
112 |
values = EnumSet.noneOf(LintCategory.class); |
|
113 |
} else { |
|
114 |
// otherwise, enable on-by-default categories |
|
115 |
values = EnumSet.noneOf(LintCategory.class); |
|
116 |
||
117 |
Source source = Source.instance(context); |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
118 |
if (source.compareTo(Source.JDK9) >= 0) { |
41637 | 119 |
values.add(LintCategory.DEP_ANN); |
120 |
} |
|
44576 | 121 |
values.add(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC); |
43588
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
122 |
values.add(LintCategory.OPENS); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41637
diff
changeset
|
123 |
values.add(LintCategory.MODULE); |
41637 | 124 |
values.add(LintCategory.REMOVAL); |
58713
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
55263
diff
changeset
|
125 |
if (!options.isSet(Option.PREVIEW)) { |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
55263
diff
changeset
|
126 |
values.add(LintCategory.PREVIEW); |
ad69fd32778e
8226585: Improve javac messages for using a preview API
jlahoda
parents:
55263
diff
changeset
|
127 |
} |
41637 | 128 |
} |
129 |
||
130 |
// Look for specific overrides |
|
131 |
for (LintCategory lc : LintCategory.values()) { |
|
132 |
if (options.isSet(Option.XLINT_CUSTOM, lc.option)) { |
|
133 |
values.add(lc); |
|
134 |
} else if (options.isSet(Option.XLINT_CUSTOM, "-" + lc.option)) { |
|
135 |
values.remove(lc); |
|
136 |
} |
|
10 | 137 |
} |
138 |
||
139 |
suppressedValues = EnumSet.noneOf(LintCategory.class); |
|
140 |
||
141 |
context.put(lintKey, this); |
|
142 |
augmentor = new AugmentVisitor(context); |
|
143 |
} |
|
144 |
||
145 |
protected Lint(Lint other) { |
|
146 |
this.augmentor = other.augmentor; |
|
147 |
this.values = other.values.clone(); |
|
148 |
this.suppressedValues = other.suppressedValues.clone(); |
|
149 |
} |
|
150 |
||
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
151 |
@Override |
10 | 152 |
public String toString() { |
153 |
return "Lint:[values" + values + " suppressedValues" + suppressedValues + "]"; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Categories of warnings that can be generated by the compiler. |
|
158 |
*/ |
|
159 |
public enum LintCategory { |
|
160 |
/** |
|
14369
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
161 |
* Warn when code refers to a auxiliary class that is hidden in a source file (ie source file name is |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
162 |
* different from the class name, and the type is not properly nested) and the referring code |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
163 |
* is not located in the same source file. |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
164 |
*/ |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
165 |
AUXILIARYCLASS("auxiliaryclass"), |
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
166 |
|
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
13689
diff
changeset
|
167 |
/** |
10 | 168 |
* Warn about use of unnecessary casts. |
169 |
*/ |
|
170 |
CAST("cast"), |
|
171 |
||
172 |
/** |
|
7624
c31b0ea95b37
6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents:
7335
diff
changeset
|
173 |
* Warn about issues related to classfile contents |
c31b0ea95b37
6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents:
7335
diff
changeset
|
174 |
*/ |
c31b0ea95b37
6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents:
7335
diff
changeset
|
175 |
CLASSFILE("classfile"), |
c31b0ea95b37
6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents:
7335
diff
changeset
|
176 |
|
c31b0ea95b37
6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents:
7335
diff
changeset
|
177 |
/** |
10 | 178 |
* Warn about use of deprecated items. |
179 |
*/ |
|
180 |
DEPRECATION("deprecation"), |
|
181 |
||
182 |
/** |
|
183 |
* Warn about items which are documented with an {@code @deprecated} JavaDoc |
|
184 |
* comment, but which do not have {@code @Deprecated} annotation. |
|
185 |
*/ |
|
186 |
DEP_ANN("dep-ann"), |
|
187 |
||
188 |
/** |
|
189 |
* Warn about division by constant integer 0. |
|
190 |
*/ |
|
191 |
DIVZERO("divzero"), |
|
192 |
||
193 |
/** |
|
194 |
* Warn about empty statement after if. |
|
195 |
*/ |
|
196 |
EMPTY("empty"), |
|
197 |
||
198 |
/** |
|
40775 | 199 |
* Warn about issues regarding module exports. |
200 |
*/ |
|
201 |
EXPORTS("exports"), |
|
202 |
||
203 |
/** |
|
10 | 204 |
* Warn about falling through from one case of a switch statement to the next. |
205 |
*/ |
|
206 |
FALLTHROUGH("fallthrough"), |
|
207 |
||
208 |
/** |
|
209 |
* Warn about finally clauses that do not terminate normally. |
|
210 |
*/ |
|
211 |
FINALLY("finally"), |
|
212 |
||
213 |
/** |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41637
diff
changeset
|
214 |
* Warn about module system related issues. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41637
diff
changeset
|
215 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41637
diff
changeset
|
216 |
MODULE("module"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41637
diff
changeset
|
217 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41637
diff
changeset
|
218 |
/** |
43588
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
219 |
* Warn about issues regarding module opens. |
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
220 |
*/ |
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
221 |
OPENS("opens"), |
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
222 |
|
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
42822
diff
changeset
|
223 |
/** |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
224 |
* Warn about issues relating to use of command line options |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
225 |
*/ |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
226 |
OPTIONS("options"), |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
227 |
|
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
228 |
/** |
19914 | 229 |
* Warn about issues regarding method overloads. |
230 |
*/ |
|
231 |
OVERLOADS("overloads"), |
|
232 |
||
233 |
/** |
|
10 | 234 |
* Warn about issues regarding method overrides. |
235 |
*/ |
|
236 |
OVERRIDES("overrides"), |
|
237 |
||
238 |
/** |
|
239 |
* Warn about invalid path elements on the command line. |
|
240 |
* Such warnings cannot be suppressed with the SuppressWarnings |
|
241 |
* annotation. |
|
242 |
*/ |
|
243 |
PATH("path"), |
|
244 |
||
245 |
/** |
|
1360
fd574e4926e3
6739427: -Xlint:processing not recognized as an option
martin
parents:
1358
diff
changeset
|
246 |
* Warn about issues regarding annotation processing. |
fd574e4926e3
6739427: -Xlint:processing not recognized as an option
martin
parents:
1358
diff
changeset
|
247 |
*/ |
fd574e4926e3
6739427: -Xlint:processing not recognized as an option
martin
parents:
1358
diff
changeset
|
248 |
PROCESSING("processing"), |
fd574e4926e3
6739427: -Xlint:processing not recognized as an option
martin
parents:
1358
diff
changeset
|
249 |
|
fd574e4926e3
6739427: -Xlint:processing not recognized as an option
martin
parents:
1358
diff
changeset
|
250 |
/** |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
251 |
* Warn about unchecked operations on raw types. |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
252 |
*/ |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
253 |
RAW("rawtypes"), |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
254 |
|
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
255 |
/** |
41637 | 256 |
* Warn about use of deprecated-for-removal items. |
257 |
*/ |
|
258 |
REMOVAL("removal"), |
|
259 |
||
260 |
/** |
|
44576 | 261 |
* Warn about use of automatic modules in the requires clauses. |
262 |
*/ |
|
263 |
REQUIRES_AUTOMATIC("requires-automatic"), |
|
264 |
||
265 |
/** |
|
266 |
* Warn about automatic modules in requires transitive. |
|
267 |
*/ |
|
268 |
REQUIRES_TRANSITIVE_AUTOMATIC("requires-transitive-automatic"), |
|
269 |
||
270 |
/** |
|
10 | 271 |
* Warn about Serializable classes that do not provide a serial version ID. |
272 |
*/ |
|
273 |
SERIAL("serial"), |
|
274 |
||
275 |
/** |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
276 |
* Warn about issues relating to use of statics |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
277 |
*/ |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
278 |
STATIC("static"), |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
279 |
|
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
280 |
/** |
55263
830ca7b43b95
8223967: Implement Text Blocks (Preview) in the Java compiler
jlaskey
parents:
49580
diff
changeset
|
281 |
* Warn about issues relating to use of text blocks |
830ca7b43b95
8223967: Implement Text Blocks (Preview) in the Java compiler
jlaskey
parents:
49580
diff
changeset
|
282 |
*/ |
830ca7b43b95
8223967: Implement Text Blocks (Preview) in the Java compiler
jlaskey
parents:
49580
diff
changeset
|
283 |
TEXT_BLOCKS("text-blocks"), |
830ca7b43b95
8223967: Implement Text Blocks (Preview) in the Java compiler
jlaskey
parents:
49580
diff
changeset
|
284 |
|
830ca7b43b95
8223967: Implement Text Blocks (Preview) in the Java compiler
jlaskey
parents:
49580
diff
changeset
|
285 |
/** |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
286 |
* Warn about issues relating to use of try blocks (i.e. try-with-resources) |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
287 |
*/ |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
288 |
TRY("try"), |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
289 |
|
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7211
diff
changeset
|
290 |
/** |
10 | 291 |
* Warn about unchecked operations on raw types. |
292 |
*/ |
|
1358 | 293 |
UNCHECKED("unchecked"), |
294 |
||
295 |
/** |
|
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5520
diff
changeset
|
296 |
* Warn about potentially unsafe vararg methods |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5520
diff
changeset
|
297 |
*/ |
49580
62b908c9f0e6
8199194: Add javac support for preview features
mcimadamore
parents:
48054
diff
changeset
|
298 |
VARARGS("varargs"), |
62b908c9f0e6
8199194: Add javac support for preview features
mcimadamore
parents:
48054
diff
changeset
|
299 |
|
62b908c9f0e6
8199194: Add javac support for preview features
mcimadamore
parents:
48054
diff
changeset
|
300 |
/** |
62b908c9f0e6
8199194: Add javac support for preview features
mcimadamore
parents:
48054
diff
changeset
|
301 |
* Warn about use of preview features. |
62b908c9f0e6
8199194: Add javac support for preview features
mcimadamore
parents:
48054
diff
changeset
|
302 |
*/ |
62b908c9f0e6
8199194: Add javac support for preview features
mcimadamore
parents:
48054
diff
changeset
|
303 |
PREVIEW("preview"); |
10 | 304 |
|
305 |
LintCategory(String option) { |
|
3661 | 306 |
this(option, false); |
307 |
} |
|
308 |
||
309 |
LintCategory(String option, boolean hidden) { |
|
10 | 310 |
this.option = option; |
3661 | 311 |
this.hidden = hidden; |
10 | 312 |
map.put(option, this); |
313 |
} |
|
314 |
||
315 |
static LintCategory get(String option) { |
|
316 |
return map.get(option); |
|
317 |
} |
|
318 |
||
168 | 319 |
public final String option; |
3661 | 320 |
public final boolean hidden; |
22163 | 321 |
} |
10 | 322 |
|
323 |
/** |
|
324 |
* Checks if a warning category is enabled. A warning category may be enabled |
|
325 |
* on the command line, or by default, and can be temporarily disabled with |
|
326 |
* the SuppressWarnings annotation. |
|
327 |
*/ |
|
328 |
public boolean isEnabled(LintCategory lc) { |
|
329 |
return values.contains(lc); |
|
330 |
} |
|
331 |
||
332 |
/** |
|
333 |
* Checks is a warning category has been specifically suppressed, by means |
|
334 |
* of the SuppressWarnings annotation, or, in the case of the deprecated |
|
335 |
* category, whether it has been implicitly suppressed by virtue of the |
|
336 |
* current entity being itself deprecated. |
|
337 |
*/ |
|
338 |
public boolean isSuppressed(LintCategory lc) { |
|
339 |
return suppressedValues.contains(lc); |
|
340 |
} |
|
341 |
||
342 |
protected static class AugmentVisitor implements Attribute.Visitor { |
|
343 |
private final Context context; |
|
344 |
private Symtab syms; |
|
345 |
private Lint parent; |
|
346 |
private Lint lint; |
|
347 |
||
348 |
AugmentVisitor(Context context) { |
|
349 |
// to break an ugly sequence of initialization dependencies, |
|
350 |
// we defer the initialization of syms until it is needed |
|
351 |
this.context = context; |
|
352 |
} |
|
353 |
||
354 |
Lint augment(Lint parent, Attribute.Compound attr) { |
|
355 |
initSyms(); |
|
356 |
this.parent = parent; |
|
357 |
lint = null; |
|
358 |
attr.accept(this); |
|
359 |
return (lint == null ? parent : lint); |
|
360 |
} |
|
361 |
||
362 |
Lint augment(Lint parent, List<Attribute.Compound> attrs) { |
|
363 |
initSyms(); |
|
364 |
this.parent = parent; |
|
365 |
lint = null; |
|
366 |
for (Attribute.Compound a: attrs) { |
|
367 |
a.accept(this); |
|
368 |
} |
|
369 |
return (lint == null ? parent : lint); |
|
370 |
} |
|
371 |
||
372 |
private void initSyms() { |
|
373 |
if (syms == null) |
|
374 |
syms = Symtab.instance(context); |
|
375 |
} |
|
376 |
||
377 |
private void suppress(LintCategory lc) { |
|
378 |
if (lint == null) |
|
379 |
lint = new Lint(parent); |
|
380 |
lint.suppressedValues.add(lc); |
|
381 |
lint.values.remove(lc); |
|
382 |
} |
|
383 |
||
384 |
public void visitConstant(Attribute.Constant value) { |
|
385 |
if (value.type.tsym == syms.stringType.tsym) { |
|
386 |
LintCategory lc = LintCategory.get((String) (value.value)); |
|
387 |
if (lc != null) |
|
388 |
suppress(lc); |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
public void visitClass(Attribute.Class clazz) { |
|
393 |
} |
|
394 |
||
395 |
// If we find a @SuppressWarnings annotation, then we continue |
|
396 |
// walking the tree, in order to suppress the individual warnings |
|
397 |
// specified in the @SuppressWarnings annotation. |
|
398 |
public void visitCompound(Attribute.Compound compound) { |
|
399 |
if (compound.type.tsym == syms.suppressWarningsType.tsym) { |
|
400 |
for (List<Pair<MethodSymbol,Attribute>> v = compound.values; |
|
401 |
v.nonEmpty(); v = v.tail) { |
|
402 |
Pair<MethodSymbol,Attribute> value = v.head; |
|
403 |
if (value.fst.name.toString().equals("value")) |
|
404 |
value.snd.accept(this); |
|
405 |
} |
|
406 |
||
407 |
} |
|
408 |
} |
|
409 |
||
410 |
public void visitArray(Attribute.Array array) { |
|
411 |
for (Attribute value : array.values) |
|
412 |
value.accept(this); |
|
413 |
} |
|
414 |
||
415 |
public void visitEnum(Attribute.Enum e) { |
|
416 |
} |
|
417 |
||
418 |
public void visitError(Attribute.Error e) { |
|
419 |
} |
|
22163 | 420 |
} |
10 | 421 |
} |