1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Apr 14 12:23:29 2010 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Apr 14 12:31:55 2010 +0100 1.3 @@ -640,6 +640,43 @@ 1.4 return true; 1.5 } 1.6 1.7 + /** Check that the type inferred using the diamond operator does not contain 1.8 + * non-denotable types such as captured types or intersection types. 1.9 + * @param t the type inferred using the diamond operator 1.10 + */ 1.11 + List<Type> checkDiamond(ClassType t) { 1.12 + DiamondTypeChecker dtc = new DiamondTypeChecker(); 1.13 + ListBuffer<Type> buf = ListBuffer.lb(); 1.14 + for (Type arg : t.getTypeArguments()) { 1.15 + if (!dtc.visit(arg, null)) { 1.16 + buf.append(arg); 1.17 + } 1.18 + } 1.19 + return buf.toList(); 1.20 + } 1.21 + 1.22 + static class DiamondTypeChecker extends Types.SimpleVisitor<Boolean, Void> { 1.23 + public Boolean visitType(Type t, Void s) { 1.24 + return true; 1.25 + } 1.26 + @Override 1.27 + public Boolean visitClassType(ClassType t, Void s) { 1.28 + if (t.isCompound()) { 1.29 + return false; 1.30 + } 1.31 + for (Type targ : t.getTypeArguments()) { 1.32 + if (!visit(targ, s)) { 1.33 + return false; 1.34 + } 1.35 + } 1.36 + return true; 1.37 + } 1.38 + @Override 1.39 + public Boolean visitCapturedType(CapturedType t, Void s) { 1.40 + return false; 1.41 + } 1.42 + } 1.43 + 1.44 /** Check that given modifiers are legal for given symbol and 1.45 * return modifiers together with any implicit modififiers for that symbol. 1.46 * Warning: we can't use flags() here since this method