--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Apr 14 12:23:29 2010 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Apr 14 12:31:55 2010 +0100
@@ -640,6 +640,43 @@
return true;
}
+ /** Check that the type inferred using the diamond operator does not contain
+ * non-denotable types such as captured types or intersection types.
+ * @param t the type inferred using the diamond operator
+ */
+ List<Type> checkDiamond(ClassType t) {
+ DiamondTypeChecker dtc = new DiamondTypeChecker();
+ ListBuffer<Type> buf = ListBuffer.lb();
+ for (Type arg : t.getTypeArguments()) {
+ if (!dtc.visit(arg, null)) {
+ buf.append(arg);
+ }
+ }
+ return buf.toList();
+ }
+
+ static class DiamondTypeChecker extends Types.SimpleVisitor<Boolean, Void> {
+ public Boolean visitType(Type t, Void s) {
+ return true;
+ }
+ @Override
+ public Boolean visitClassType(ClassType t, Void s) {
+ if (t.isCompound()) {
+ return false;
+ }
+ for (Type targ : t.getTypeArguments()) {
+ if (!visit(targ, s)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ @Override
+ public Boolean visitCapturedType(CapturedType t, Void s) {
+ return false;
+ }
+ }
+
/** Check that given modifiers are legal for given symbol and
* return modifiers together with any implicit modififiers for that symbol.
* Warning: we can't use flags() here since this method