src/share/classes/com/sun/tools/javac/comp/Check.java

changeset 2028
4ce8148ffc4f
parent 2024
5d2d484a1216
child 2038
8d1c48de706d
equal deleted inserted replaced
2027:4932bb04c4b8 2028:4ce8148ffc4f
146 uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, 146 uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
147 enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); 147 enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
148 sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi, 148 sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
149 enforceMandatoryWarnings, "sunapi", null); 149 enforceMandatoryWarnings, "sunapi", null);
150 150
151 deferredLintHandler = DeferredLintHandler.immediateHandler; 151 deferredLintHandler = DeferredLintHandler.instance(context);
152 } 152 }
153 153
154 /** Switch: generics enabled? 154 /** Switch: generics enabled?
155 */ 155 */
156 boolean allowGenerics; 156 boolean allowGenerics;
213 **************************************************************************/ 213 **************************************************************************/
214 214
215 Lint setLint(Lint newLint) { 215 Lint setLint(Lint newLint) {
216 Lint prev = lint; 216 Lint prev = lint;
217 lint = newLint; 217 lint = newLint;
218 return prev;
219 }
220
221 /* This idiom should be used only in cases when it is needed to set the lint
222 * of an environment that has been created in a phase previous to annotations
223 * processing.
224 */
225 Lint getLint() {
226 return lint;
227 }
228
229 DeferredLintHandler setDeferredLintHandler(DeferredLintHandler newDeferredLintHandler) {
230 DeferredLintHandler prev = deferredLintHandler;
231 deferredLintHandler = newDeferredLintHandler;
232 return prev; 218 return prev;
233 } 219 }
234 220
235 MethodSymbol setMethod(MethodSymbol newMethod) { 221 MethodSymbol setMethod(MethodSymbol newMethod) {
236 MethodSymbol prev = method; 222 MethodSymbol prev = method;
580 } 566 }
581 567
582 /** Check for redundant casts (i.e. where source type is a subtype of target type) 568 /** Check for redundant casts (i.e. where source type is a subtype of target type)
583 * The problem should only be reported for non-292 cast 569 * The problem should only be reported for non-292 cast
584 */ 570 */
585 public void checkRedundantCast(Env<AttrContext> env, JCTypeCast tree) { 571 public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) {
586 if (!tree.type.isErroneous() && 572 if (!tree.type.isErroneous()
587 (env.info.lint == null || env.info.lint.isEnabled(Lint.LintCategory.CAST))
588 && types.isSameType(tree.expr.type, tree.clazz.type) 573 && types.isSameType(tree.expr.type, tree.clazz.type)
589 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz)) 574 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
590 && !is292targetTypeCast(tree)) { 575 && !is292targetTypeCast(tree)) {
591 log.warning(Lint.LintCategory.CAST, 576 deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
592 tree.pos(), "redundant.cast", tree.expr.type); 577 @Override
578 public void report() {
579 if (lint.isEnabled(Lint.LintCategory.CAST))
580 log.warning(Lint.LintCategory.CAST,
581 tree.pos(), "redundant.cast", tree.expr.type);
582 }
583 });
593 } 584 }
594 } 585 }
595 //where 586 //where
596 private boolean is292targetTypeCast(JCTypeCast tree) { 587 private boolean is292targetTypeCast(JCTypeCast tree) {
597 boolean is292targetTypeCast = false; 588 boolean is292targetTypeCast = false;

mercurial