1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Jun 26 12:22:40 2009 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Jun 26 18:51:39 2009 -0700 1.3 @@ -1245,6 +1245,11 @@ 1.4 } 1.5 } 1.6 1.7 + public void visitAnnotatedType(JCAnnotatedType tree) { 1.8 + // annotations don't get scanned 1.9 + tree.underlyingType.accept(this); 1.10 + } 1.11 + 1.12 public void visitIdent(JCIdent tree) { 1.13 if (tree.sym.kind == VAR) 1.14 checkInit(tree.pos(), (VarSymbol)tree.sym); 1.15 @@ -1254,7 +1259,8 @@ 1.16 super.visitTypeCast(tree); 1.17 if (!tree.type.isErroneous() 1.18 && lint.isEnabled(Lint.LintCategory.CAST) 1.19 - && types.isSameType(tree.expr.type, tree.clazz.type)) { 1.20 + && types.isSameType(tree.expr.type, tree.clazz.type) 1.21 + && !(ignoreAnnotatedCasts && containsTypeAnnotation(tree.clazz))) { 1.22 log.warning(tree.pos(), "redundant.cast", tree.expr.type); 1.23 } 1.24 } 1.25 @@ -1264,6 +1270,23 @@ 1.26 } 1.27 1.28 /************************************************************************** 1.29 + * utility methods for ignoring type-annotated casts lint checking 1.30 + *************************************************************************/ 1.31 + private static final boolean ignoreAnnotatedCasts = true; 1.32 + private static class AnnotationFinder extends TreeScanner { 1.33 + public boolean foundTypeAnno = false; 1.34 + public void visitAnnotation(JCAnnotation tree) { 1.35 + foundTypeAnno = foundTypeAnno || (tree instanceof JCTypeAnnotation); 1.36 + } 1.37 + } 1.38 + 1.39 + private boolean containsTypeAnnotation(JCTree e) { 1.40 + AnnotationFinder finder = new AnnotationFinder(); 1.41 + finder.scan(e); 1.42 + return finder.foundTypeAnno; 1.43 + } 1.44 + 1.45 +/************************************************************************** 1.46 * main method 1.47 *************************************************************************/ 1.48