diff -r ca063536e4a6 -r 03944ee4fac4 src/share/classes/com/sun/tools/javac/comp/Flow.java --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Jun 26 12:22:40 2009 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Jun 26 18:51:39 2009 -0700 @@ -1245,6 +1245,11 @@ } } + public void visitAnnotatedType(JCAnnotatedType tree) { + // annotations don't get scanned + tree.underlyingType.accept(this); + } + public void visitIdent(JCIdent tree) { if (tree.sym.kind == VAR) checkInit(tree.pos(), (VarSymbol)tree.sym); @@ -1254,7 +1259,8 @@ super.visitTypeCast(tree); if (!tree.type.isErroneous() && lint.isEnabled(Lint.LintCategory.CAST) - && types.isSameType(tree.expr.type, tree.clazz.type)) { + && types.isSameType(tree.expr.type, tree.clazz.type) + && !(ignoreAnnotatedCasts && containsTypeAnnotation(tree.clazz))) { log.warning(tree.pos(), "redundant.cast", tree.expr.type); } } @@ -1264,6 +1270,23 @@ } /************************************************************************** + * utility methods for ignoring type-annotated casts lint checking + *************************************************************************/ + private static final boolean ignoreAnnotatedCasts = true; + private static class AnnotationFinder extends TreeScanner { + public boolean foundTypeAnno = false; + public void visitAnnotation(JCAnnotation tree) { + foundTypeAnno = foundTypeAnno || (tree instanceof JCTypeAnnotation); + } + } + + private boolean containsTypeAnnotation(JCTree e) { + AnnotationFinder finder = new AnnotationFinder(); + finder.scan(e); + return finder.foundTypeAnno; + } + +/************************************************************************** * main method *************************************************************************/