1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 19 11:50:50 2010 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 19 11:52:58 2010 +0100 1.3 @@ -906,33 +906,15 @@ 1.4 * 1.5 * and we can't make sure that the bound is already attributed because 1.6 * of possible cycles. 1.7 - */ 1.8 - private Validator validator = new Validator(); 1.9 - 1.10 - /** Visitor method: Validate a type expression, if it is not null, catching 1.11 + * 1.12 + * Visitor method: Validate a type expression, if it is not null, catching 1.13 * and reporting any completion failures. 1.14 */ 1.15 void validate(JCTree tree, Env<AttrContext> env) { 1.16 - try { 1.17 - if (tree != null) { 1.18 - validator.env = env; 1.19 - tree.accept(validator); 1.20 - checkRaw(tree, env); 1.21 - } 1.22 - } catch (CompletionFailure ex) { 1.23 - completionError(tree.pos(), ex); 1.24 - } 1.25 + validate(tree, env, true); 1.26 } 1.27 - //where 1.28 - void checkRaw(JCTree tree, Env<AttrContext> env) { 1.29 - if (lint.isEnabled(Lint.LintCategory.RAW) && 1.30 - tree.type.tag == CLASS && 1.31 - !TreeInfo.isDiamond(tree) && 1.32 - !env.enclClass.name.isEmpty() && //anonymous or intersection 1.33 - tree.type.isRaw()) { 1.34 - log.warning(Lint.LintCategory.RAW, 1.35 - tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type); 1.36 - } 1.37 + void validate(JCTree tree, Env<AttrContext> env, boolean checkRaw) { 1.38 + new Validator(env).validateTree(tree, checkRaw, true); 1.39 } 1.40 1.41 /** Visitor method: Validate a list of type expressions. 1.42 @@ -946,9 +928,16 @@ 1.43 */ 1.44 class Validator extends JCTree.Visitor { 1.45 1.46 + boolean isOuter; 1.47 + Env<AttrContext> env; 1.48 + 1.49 + Validator(Env<AttrContext> env) { 1.50 + this.env = env; 1.51 + } 1.52 + 1.53 @Override 1.54 public void visitTypeArray(JCArrayTypeTree tree) { 1.55 - validate(tree.elemtype, env); 1.56 + tree.elemtype.accept(this); 1.57 } 1.58 1.59 @Override 1.60 @@ -960,10 +949,14 @@ 1.61 List<Type> forms = tree.type.tsym.type.getTypeArguments(); 1.62 ListBuffer<Type> tvars_buf = new ListBuffer<Type>(); 1.63 1.64 + boolean is_java_lang_Class = tree.type.tsym.flatName() == names.java_lang_Class; 1.65 + 1.66 // For matching pairs of actual argument types `a' and 1.67 // formal type parameters with declared bound `b' ... 1.68 while (args.nonEmpty() && forms.nonEmpty()) { 1.69 - validate(args.head, env); 1.70 + validateTree(args.head, 1.71 + !(isOuter && is_java_lang_Class), 1.72 + false); 1.73 1.74 // exact type arguments needs to know their 1.75 // bounds (for upper and lower bound 1.76 @@ -1015,14 +1008,14 @@ 1.77 1.78 @Override 1.79 public void visitTypeParameter(JCTypeParameter tree) { 1.80 - validate(tree.bounds, env); 1.81 + validateTrees(tree.bounds, true, isOuter); 1.82 checkClassBounds(tree.pos(), tree.type); 1.83 } 1.84 1.85 @Override 1.86 public void visitWildcard(JCWildcard tree) { 1.87 if (tree.inner != null) 1.88 - validate(tree.inner, env); 1.89 + validateTree(tree.inner, true, isOuter); 1.90 } 1.91 1.92 @Override 1.93 @@ -1060,7 +1053,34 @@ 1.94 public void visitTree(JCTree tree) { 1.95 } 1.96 1.97 - Env<AttrContext> env; 1.98 + public void validateTree(JCTree tree, boolean checkRaw, boolean isOuter) { 1.99 + try { 1.100 + if (tree != null) { 1.101 + this.isOuter = isOuter; 1.102 + tree.accept(this); 1.103 + if (checkRaw) 1.104 + checkRaw(tree, env); 1.105 + } 1.106 + } catch (CompletionFailure ex) { 1.107 + completionError(tree.pos(), ex); 1.108 + } 1.109 + } 1.110 + 1.111 + public void validateTrees(List<? extends JCTree> trees, boolean checkRaw, boolean isOuter) { 1.112 + for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) 1.113 + validateTree(l.head, checkRaw, isOuter); 1.114 + } 1.115 + 1.116 + void checkRaw(JCTree tree, Env<AttrContext> env) { 1.117 + if (lint.isEnabled(Lint.LintCategory.RAW) && 1.118 + tree.type.tag == CLASS && 1.119 + !TreeInfo.isDiamond(tree) && 1.120 + !env.enclClass.name.isEmpty() && //anonymous or intersection 1.121 + tree.type.isRaw()) { 1.122 + log.warning(Lint.LintCategory.RAW, 1.123 + tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type); 1.124 + } 1.125 + } 1.126 } 1.127 1.128 /* *************************************************************************