Wed, 02 Mar 2011 21:13:55 -0800
6639645: Modeling type implementing missing interfaces
Reviewed-by: darcy, mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Wed Mar 02 21:06:17 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Wed Mar 02 21:13:55 2011 -0800 1.3 @@ -43,7 +43,7 @@ 1.4 private Flags() {} // uninstantiable 1.5 1.6 public static String toString(long flags) { 1.7 - StringBuffer buf = new StringBuffer(); 1.8 + StringBuilder buf = new StringBuilder(); 1.9 String sep = ""; 1.10 for (Flag s : asFlagSet(flags)) { 1.11 buf.append(sep);
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Wed Mar 02 21:06:17 2011 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Wed Mar 02 21:13:55 2011 -0800 2.3 @@ -831,6 +831,8 @@ 2.4 ClassType t = (ClassType)type; 2.5 if (t.interfaces_field == null) // FIXME: shouldn't be null 2.6 t.interfaces_field = List.nil(); 2.7 + if (t.all_interfaces_field != null) 2.8 + return Type.getModelTypes(t.all_interfaces_field); 2.9 return t.interfaces_field; 2.10 } else { 2.11 return List.nil(); 2.12 @@ -846,7 +848,7 @@ 2.13 // An interface has no superclass; its supertype is Object. 2.14 return t.isInterface() 2.15 ? Type.noType 2.16 - : t.supertype_field; 2.17 + : t.supertype_field.getModelType(); 2.18 } else { 2.19 return Type.noType; 2.20 }
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Wed Mar 02 21:06:17 2011 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Wed Mar 02 21:13:55 2011 -0800 3.3 @@ -93,6 +93,22 @@ 3.4 return null; 3.5 } 3.6 3.7 + /** 3.8 + * Get the representation of this type used for modelling purposes. 3.9 + * By default, this is itself. For ErrorType, a different value 3.10 + * may be provided, 3.11 + */ 3.12 + public Type getModelType() { 3.13 + return this; 3.14 + } 3.15 + 3.16 + public static List<Type> getModelTypes(List<Type> ts) { 3.17 + ListBuffer<Type> lb = new ListBuffer<Type>(); 3.18 + for (Type t: ts) 3.19 + lb.append(t.getModelType()); 3.20 + return lb.toList(); 3.21 + } 3.22 + 3.23 public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } 3.24 3.25 /** Define a type given its tag and type symbol 3.26 @@ -190,7 +206,7 @@ 3.27 if (ts.isEmpty()) { 3.28 return ""; 3.29 } else { 3.30 - StringBuffer buf = new StringBuffer(); 3.31 + StringBuilder buf = new StringBuilder(); 3.32 buf.append(ts.head.toString()); 3.33 for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail) 3.34 buf.append(",").append(l.head.toString()); 3.35 @@ -464,7 +480,7 @@ 3.36 3.37 boolean isPrintingBound = false; 3.38 public String toString() { 3.39 - StringBuffer s = new StringBuffer(); 3.40 + StringBuilder s = new StringBuilder(); 3.41 s.append(kind.toString()); 3.42 if (kind != UNBOUND) 3.43 s.append(type); 3.44 @@ -538,6 +554,10 @@ 3.45 */ 3.46 public List<Type> interfaces_field; 3.47 3.48 + /** All the interfaces of this class, including missing ones. 3.49 + */ 3.50 + public List<Type> all_interfaces_field; 3.51 + 3.52 public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { 3.53 super(CLASS, tsym); 3.54 this.outer_field = outer; 3.55 @@ -578,7 +598,7 @@ 3.56 /** The Java source which this type represents. 3.57 */ 3.58 public String toString() { 3.59 - StringBuffer buf = new StringBuffer(); 3.60 + StringBuilder buf = new StringBuilder(); 3.61 if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) { 3.62 buf.append(getEnclosingType().toString()); 3.63 buf.append("."); 3.64 @@ -596,7 +616,7 @@ 3.65 //where 3.66 private String className(Symbol sym, boolean longform) { 3.67 if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) { 3.68 - StringBuffer s = new StringBuffer(supertype_field.toString()); 3.69 + StringBuilder s = new StringBuilder(supertype_field.toString()); 3.70 for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) { 3.71 s.append("&"); 3.72 s.append(is.head.toString());
4.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Wed Mar 02 21:06:17 2011 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Wed Mar 02 21:13:55 2011 -0800 4.3 @@ -2534,7 +2534,7 @@ 4.4 } 4.5 // where 4.6 private String typaramsString(List<Type> tvars) { 4.7 - StringBuffer s = new StringBuffer(); 4.8 + StringBuilder s = new StringBuilder(); 4.9 s.append('<'); 4.10 boolean first = true; 4.11 for (Type t : tvars) { 4.12 @@ -2545,7 +2545,7 @@ 4.13 s.append('>'); 4.14 return s.toString(); 4.15 } 4.16 - private void appendTyparamString(TypeVar t, StringBuffer buf) { 4.17 + private void appendTyparamString(TypeVar t, StringBuilder buf) { 4.18 buf.append(t); 4.19 if (t.bound == null || 4.20 t.bound.tsym.getQualifiedName() == names.java_lang_Object)
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Mar 02 21:06:17 2011 -0800 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Mar 02 21:13:55 2011 -0800 5.3 @@ -2980,7 +2980,7 @@ 5.4 // (see comment for TypeVar.bound). 5.5 // In this case, generate a class tree that represents the 5.6 // bound class, ... 5.7 - JCTree extending; 5.8 + JCExpression extending; 5.9 List<JCExpression> implementing; 5.10 if ((bs.head.tsym.flags() & INTERFACE) == 0) { 5.11 extending = tree.bounds.head;
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Mar 02 21:06:17 2011 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Mar 02 21:13:55 2011 -0800 6.3 @@ -889,10 +889,11 @@ 6.4 : (c.fullname == names.java_lang_Object) 6.5 ? Type.noType 6.6 : syms.objectType; 6.7 - ct.supertype_field = supertype; 6.8 + ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); 6.9 6.10 // Determine interfaces. 6.11 ListBuffer<Type> interfaces = new ListBuffer<Type>(); 6.12 + ListBuffer<Type> all_interfaces = null; // lazy init 6.13 Set<Type> interfaceSet = new HashSet<Type>(); 6.14 List<JCExpression> interfaceTrees = tree.implementing; 6.15 if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) { 6.16 @@ -909,13 +910,22 @@ 6.17 Type i = attr.attribBase(iface, baseEnv, false, true, true); 6.18 if (i.tag == CLASS) { 6.19 interfaces.append(i); 6.20 + if (all_interfaces != null) all_interfaces.append(i); 6.21 chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); 6.22 + } else { 6.23 + if (all_interfaces == null) 6.24 + all_interfaces = new ListBuffer<Type>().appendList(interfaces); 6.25 + all_interfaces.append(modelMissingTypes(i, iface, true)); 6.26 } 6.27 } 6.28 - if ((c.flags_field & ANNOTATION) != 0) 6.29 + if ((c.flags_field & ANNOTATION) != 0) { 6.30 ct.interfaces_field = List.of(syms.annotationType); 6.31 - else 6.32 + ct.all_interfaces_field = ct.interfaces_field; 6.33 + } else { 6.34 ct.interfaces_field = interfaces.toList(); 6.35 + ct.all_interfaces_field = (all_interfaces == null) 6.36 + ? ct.interfaces_field : all_interfaces.toList(); 6.37 + } 6.38 6.39 if (c.fullname == names.java_lang_Object) { 6.40 if (tree.extending != null) { 6.41 @@ -1066,6 +1076,125 @@ 6.42 return result; 6.43 } 6.44 6.45 + Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) { 6.46 + if (t.tag != ERROR) 6.47 + return t; 6.48 + 6.49 + return new ErrorType(((ErrorType) t).getOriginalType(), t.tsym) { 6.50 + private Type modelType; 6.51 + 6.52 + @Override 6.53 + public Type getModelType() { 6.54 + if (modelType == null) 6.55 + modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree); 6.56 + return modelType; 6.57 + } 6.58 + }; 6.59 + } 6.60 + // where 6.61 + private class Synthesizer extends JCTree.Visitor { 6.62 + Type originalType; 6.63 + boolean interfaceExpected; 6.64 + List<ClassSymbol> synthesizedSymbols = List.nil(); 6.65 + Type result; 6.66 + 6.67 + Synthesizer(Type originalType, boolean interfaceExpected) { 6.68 + this.originalType = originalType; 6.69 + this.interfaceExpected = interfaceExpected; 6.70 + } 6.71 + 6.72 + Type visit(JCTree tree) { 6.73 + tree.accept(this); 6.74 + return result; 6.75 + } 6.76 + 6.77 + List<Type> visit(List<? extends JCTree> trees) { 6.78 + ListBuffer<Type> lb = new ListBuffer<Type>(); 6.79 + for (JCTree t: trees) 6.80 + lb.append(visit(t)); 6.81 + return lb.toList(); 6.82 + } 6.83 + 6.84 + @Override 6.85 + public void visitTree(JCTree tree) { 6.86 + result = syms.errType; 6.87 + } 6.88 + 6.89 + @Override 6.90 + public void visitIdent(JCIdent tree) { 6.91 + if (tree.type.tag != ERROR) { 6.92 + result = tree.type; 6.93 + } else { 6.94 + result = synthesizeClass(tree.name, syms.unnamedPackage).type; 6.95 + } 6.96 + } 6.97 + 6.98 + @Override 6.99 + public void visitSelect(JCFieldAccess tree) { 6.100 + if (tree.type.tag != ERROR) { 6.101 + result = tree.type; 6.102 + } else { 6.103 + Type selectedType; 6.104 + boolean prev = interfaceExpected; 6.105 + try { 6.106 + interfaceExpected = false; 6.107 + selectedType = visit(tree.selected); 6.108 + } finally { 6.109 + interfaceExpected = prev; 6.110 + } 6.111 + ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym); 6.112 + result = c.type; 6.113 + } 6.114 + } 6.115 + 6.116 + @Override 6.117 + public void visitTypeApply(JCTypeApply tree) { 6.118 + if (tree.type.tag != ERROR) { 6.119 + result = tree.type; 6.120 + } else { 6.121 + ClassType clazzType = (ClassType) visit(tree.clazz); 6.122 + if (synthesizedSymbols.contains(clazzType.tsym)) 6.123 + synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size()); 6.124 + final List<Type> actuals = visit(tree.arguments); 6.125 + result = new ErrorType(tree.type, clazzType.tsym) { 6.126 + @Override 6.127 + public List<Type> getTypeArguments() { 6.128 + return actuals; 6.129 + } 6.130 + }; 6.131 + } 6.132 + } 6.133 + 6.134 + ClassSymbol synthesizeClass(Name name, Symbol owner) { 6.135 + int flags = interfaceExpected ? INTERFACE : 0; 6.136 + ClassSymbol c = new ClassSymbol(flags, name, owner); 6.137 + c.members_field = new Scope.ErrorScope(c); 6.138 + c.type = new ErrorType(originalType, c) { 6.139 + @Override 6.140 + public List<Type> getTypeArguments() { 6.141 + return typarams_field; 6.142 + } 6.143 + }; 6.144 + synthesizedSymbols = synthesizedSymbols.prepend(c); 6.145 + return c; 6.146 + } 6.147 + 6.148 + void synthesizeTyparams(ClassSymbol sym, int n) { 6.149 + ClassType ct = (ClassType) sym.type; 6.150 + Assert.check(ct.typarams_field.isEmpty()); 6.151 + if (n == 1) { 6.152 + TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType); 6.153 + ct.typarams_field = ct.typarams_field.prepend(v); 6.154 + } else { 6.155 + for (int i = n; i > 0; i--) { 6.156 + TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType); 6.157 + ct.typarams_field = ct.typarams_field.prepend(v); 6.158 + } 6.159 + } 6.160 + } 6.161 + } 6.162 + 6.163 + 6.164 /* *************************************************************************** 6.165 * tree building 6.166 ****************************************************************************/
7.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Mar 02 21:06:17 2011 -0800 7.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Mar 02 21:13:55 2011 -0800 7.3 @@ -2357,7 +2357,7 @@ 7.4 7.5 List<JCTypeParameter> typarams = typeParametersOpt(); 7.6 7.7 - JCTree extending = null; 7.8 + JCExpression extending = null; 7.9 if (S.token() == EXTENDS) { 7.10 S.nextToken(); 7.11 extending = parseType();
8.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Wed Mar 02 21:06:17 2011 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Wed Mar 02 21:13:55 2011 -0800 8.3 @@ -567,14 +567,14 @@ 8.4 public JCModifiers mods; 8.5 public Name name; 8.6 public List<JCTypeParameter> typarams; 8.7 - public JCTree extending; 8.8 + public JCExpression extending; 8.9 public List<JCExpression> implementing; 8.10 public List<JCTree> defs; 8.11 public ClassSymbol sym; 8.12 protected JCClassDecl(JCModifiers mods, 8.13 Name name, 8.14 List<JCTypeParameter> typarams, 8.15 - JCTree extending, 8.16 + JCExpression extending, 8.17 List<JCExpression> implementing, 8.18 List<JCTree> defs, 8.19 ClassSymbol sym) 8.20 @@ -2104,7 +2104,7 @@ 8.21 JCClassDecl ClassDef(JCModifiers mods, 8.22 Name name, 8.23 List<JCTypeParameter> typarams, 8.24 - JCTree extending, 8.25 + JCExpression extending, 8.26 List<JCExpression> implementing, 8.27 List<JCTree> defs); 8.28 JCMethodDecl MethodDef(JCModifiers mods,
9.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java Wed Mar 02 21:06:17 2011 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java Wed Mar 02 21:13:55 2011 -0800 9.3 @@ -135,7 +135,7 @@ 9.4 JCClassDecl t = (JCClassDecl) node; 9.5 JCModifiers mods = copy(t.mods, p); 9.6 List<JCTypeParameter> typarams = copy(t.typarams, p); 9.7 - JCTree extending = copy(t.extending, p); 9.8 + JCExpression extending = copy(t.extending, p); 9.9 List<JCExpression> implementing = copy(t.implementing, p); 9.10 List<JCTree> defs = copy(t.defs, p); 9.11 return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
10.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Wed Mar 02 21:06:17 2011 -0800 10.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Wed Mar 02 21:13:55 2011 -0800 10.3 @@ -146,7 +146,7 @@ 10.4 public JCClassDecl ClassDef(JCModifiers mods, 10.5 Name name, 10.6 List<JCTypeParameter> typarams, 10.7 - JCTree extending, 10.8 + JCExpression extending, 10.9 List<JCExpression> implementing, 10.10 List<JCTree> defs) 10.11 {
11.1 --- a/test/tools/javac/api/6557752/T6557752.java Wed Mar 02 21:06:17 2011 -0800 11.2 +++ b/test/tools/javac/api/6557752/T6557752.java Wed Mar 02 21:13:55 2011 -0800 11.3 @@ -1,5 +1,5 @@ 11.4 /* 11.5 - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. 11.6 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. 11.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.8 * 11.9 * This code is free software; you can redistribute it and/or modify it 11.10 @@ -119,7 +119,7 @@ 11.11 Types types = task.getTypes(); 11.12 11.13 if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) { 11.14 - throw new AssertionError("Ttypes.asElement() error!"); 11.15 + throw new AssertionError("Types.asElement() error!"); 11.16 } 11.17 foundError = true; 11.18 }
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement/InvalidSource.java Wed Mar 02 21:13:55 2011 -0800 12.3 @@ -0,0 +1,108 @@ 12.4 +/* 12.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +import java.util.*; 12.28 + 12.29 +@interface ExpectInterfaces { 12.30 + String value(); 12.31 +} 12.32 + 12.33 +@interface ExpectSupertype { 12.34 + String value(); 12.35 +} 12.36 + 12.37 +interface OK { 12.38 + void m(); 12.39 +} 12.40 + 12.41 +class InvalidSource { 12.42 + /* 12.43 + * The following annotations contain a simple description of the expected 12.44 + * representation of the superclass and superinterfaces of the corresponding 12.45 + * elements. 12.46 + * The strings contain a comma-separated list of descriptions. 12.47 + * Descriptions are composed as follows: 12.48 + * A leading "!:" indicates the type mirror has kind ERROR. 12.49 + * "empty" means that the corresponding element has no enclosed elements. 12.50 + * "clss", "intf" and "tvar" indicate the name refers to a class, interface 12.51 + * or type variable. Each is followed by the declared name of the element. 12.52 + * "pkg" indicates the name of a package element. 12.53 + * An enclosing element is shown in parentheses. 12.54 + * A trailing "!" indicates that the element's type has kind ERROR. 12.55 + */ 12.56 + 12.57 + @ExpectSupertype("!:empty clss A!") 12.58 + class TestClassMissingClassA extends A { } 12.59 + 12.60 + @ExpectSupertype("!:empty clss (pkg A).B!") 12.61 + class TestClassMissingClassAB extends A.B { } 12.62 + 12.63 + @ExpectSupertype("!:empty clss (pkg java.util).A!") 12.64 + class TestClassMissingClass_juA extends java.util.A { } 12.65 + 12.66 + @ExpectSupertype("!:empty clss A!<tvar T>") 12.67 + class TestClassTMissingClassAT<T> extends A<T> { } 12.68 + 12.69 + @ExpectInterfaces("!:empty intf A!") 12.70 + class TestClassMissingIntfA implements A { } 12.71 + 12.72 + @ExpectInterfaces("!:empty intf (pkg A).B!") 12.73 + class TestClassMissingIntfAB implements A.B { } 12.74 + 12.75 + @ExpectInterfaces("!:empty intf A!, intf OK") 12.76 + abstract class TestClassMissingIntfAOK implements A, OK { } 12.77 + 12.78 + @ExpectInterfaces("intf OK, !:empty intf A!") 12.79 + abstract class TestClassOKMissingIntfA implements OK, A { } 12.80 + 12.81 + @ExpectInterfaces("!:empty intf A!, !:empty intf B!") 12.82 + class TestClassMissingIntfA_B implements A, B { } 12.83 + 12.84 + @ExpectInterfaces("!:empty intf A!") 12.85 + interface TestIntfMissingIntfA extends A { } 12.86 + 12.87 + @ExpectInterfaces("!:empty intf A!, intf OK") 12.88 + interface TestIntfMissingIntfAOK extends A, OK { } 12.89 + 12.90 + @ExpectInterfaces("intf OK, !:empty intf A!") 12.91 + interface TestIntfOKMissingIntfA extends OK, A { } 12.92 + 12.93 + @ExpectInterfaces("!:empty intf A!, !:empty intf B!") 12.94 + interface TestIntfMissingIntfAB extends A, B { } 12.95 + 12.96 + @ExpectInterfaces("!:empty intf A!<tvar T>") 12.97 + class TestClassTMissingIntfAT<T> implements A<T> { } 12.98 + 12.99 + @ExpectInterfaces("!:empty intf A!<tvar T>, !:empty intf B!") 12.100 + class TestClassTMissingIntfAT_B<T> implements A<T>, B { } 12.101 + 12.102 + @ExpectInterfaces("!:empty intf A!<tvar T>") 12.103 + interface TestIntfTMissingIntfAT<T> extends A<T> { } 12.104 + 12.105 + @ExpectInterfaces("!:empty intf A!<tvar T>, !:empty intf B!") 12.106 + interface TestIntfTMissingIntfAT_B<T> extends A<T>, B { } 12.107 + 12.108 + @ExpectInterfaces("intf (pkg java.util).List<!:empty clss X!>") 12.109 + abstract class TestClassListMissingX implements List<X> { } 12.110 +} 12.111 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Wed Mar 02 21:13:55 2011 -0800 13.3 @@ -0,0 +1,185 @@ 13.4 +/* 13.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 + 13.28 +/* 13.29 + * @test 13.30 + * @bug 6639645 13.31 + * @summary Modeling type implementing missing interfaces 13.32 + * @library ../../../../lib 13.33 + * @build JavacTestingAbstractProcessor TestMissingElement 13.34 + * @compile -proc:only -XprintRounds -processor TestMissingElement InvalidSource.java 13.35 + */ 13.36 + 13.37 +import java.util.*; 13.38 +import javax.annotation.processing.*; 13.39 +import javax.lang.model.element.*; 13.40 +import javax.lang.model.type.*; 13.41 +import javax.lang.model.util.*; 13.42 +import static javax.tools.Diagnostic.Kind.*; 13.43 + 13.44 +public class TestMissingElement extends JavacTestingAbstractProcessor { 13.45 + @Override 13.46 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 13.47 + for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) { 13.48 + if (isSimpleName(te, "InvalidSource")) { 13.49 + for (Element c: te.getEnclosedElements()) { 13.50 + for (AnnotationMirror am: c.getAnnotationMirrors()) { 13.51 + Element ate = am.getAnnotationType().asElement(); 13.52 + if (isSimpleName(ate, "ExpectInterfaces")) { 13.53 + checkInterfaces((TypeElement) c, getValue(am)); 13.54 + } else if (isSimpleName(ate, "ExpectSupertype")) { 13.55 + checkSupertype((TypeElement) c, getValue(am)); 13.56 + } 13.57 + } 13.58 + } 13.59 + } 13.60 + } 13.61 + return true; 13.62 + } 13.63 + 13.64 + private boolean isSimpleName(Element e, String name) { 13.65 + return e.getSimpleName().contentEquals(name); 13.66 + } 13.67 + 13.68 + private String getValue(AnnotationMirror am) { 13.69 + Map<? extends ExecutableElement, ? extends AnnotationValue> map = am.getElementValues(); 13.70 + if (map.size() != 1) throw new IllegalArgumentException(); 13.71 + AnnotationValue v = map.values().iterator().next(); 13.72 + return (String) v.getValue(); 13.73 + } 13.74 + 13.75 + private void checkInterfaces(TypeElement te, String expect) { 13.76 + System.err.println("check interfaces: " + te + " -- " + expect); 13.77 + String found = asString(te.getInterfaces(), ", "); 13.78 + checkEqual("interfaces", te, found, expect); 13.79 + } 13.80 + 13.81 + private void checkSupertype(TypeElement te, String expect) { 13.82 + System.err.println("check supertype: " + te + " -- " + expect); 13.83 + String found = asString(te.getSuperclass()); 13.84 + checkEqual("supertype", te, found, expect); 13.85 + } 13.86 + 13.87 + private void checkEqual(String label, TypeElement te, String found, String expect) { 13.88 + if (found.equals(expect)) { 13.89 +// messager.printMessage(NOTE, "expected " + label + " found: " + expect, te); 13.90 + } else { 13.91 + System.err.println("unexpected " + label + ": " + te + "\n" 13.92 + + " found: " + found + "\n" 13.93 + + "expect: " + expect); 13.94 + messager.printMessage(ERROR, "unexpected " + label + " found: " + found + "; expected: " + expect, te); 13.95 + } 13.96 + } 13.97 + 13.98 + private String asString(List<? extends TypeMirror> ts, String sep) { 13.99 + StringBuilder sb = new StringBuilder(); 13.100 + for (TypeMirror t: ts) { 13.101 + if (sb.length() != 0) sb.append(sep); 13.102 + sb.append(asString(t)); 13.103 + } 13.104 + return sb.toString(); 13.105 + } 13.106 + 13.107 + private String asString(TypeMirror t) { 13.108 + if (t == null) 13.109 + return "[typ:null]"; 13.110 + return t.accept(new SimpleTypeVisitor7<String, Void>() { 13.111 + @Override 13.112 + public String defaultAction(TypeMirror t, Void ignore) { 13.113 + return "[typ:" + t.toString() + "]"; 13.114 + } 13.115 + 13.116 + @Override 13.117 + public String visitDeclared(DeclaredType t, Void ignore) { 13.118 + String s = asString(t.asElement()); 13.119 + List<? extends TypeMirror> args = t.getTypeArguments(); 13.120 + if (!args.isEmpty()) 13.121 + s += "<" + asString(args, ",") + ">"; 13.122 + return s; 13.123 + } 13.124 + 13.125 + @Override 13.126 + public String visitTypeVariable(TypeVariable t, Void ignore) { 13.127 + return "tvar " + t; 13.128 + } 13.129 + 13.130 + @Override 13.131 + public String visitError(ErrorType t, Void ignore) { 13.132 + return "!:" + visitDeclared(t, ignore); 13.133 + } 13.134 + }, null); 13.135 + } 13.136 + 13.137 + private String asString(Element e) { 13.138 + if (e == null) 13.139 + return "[elt:null]"; 13.140 + return e.accept(new SimpleElementVisitor7<String, Void>() { 13.141 + @Override 13.142 + public String defaultAction(Element e, Void ignore) { 13.143 + return "[elt:" + e.getKind() + " " + e.toString() + "]"; 13.144 + } 13.145 + @Override 13.146 + public String visitPackage(PackageElement e, Void ignore) { 13.147 + return "pkg " + e.getQualifiedName(); 13.148 + } 13.149 + @Override 13.150 + public String visitType(TypeElement e, Void ignore) { 13.151 + StringBuilder sb = new StringBuilder(); 13.152 + if (e.getEnclosedElements().isEmpty()) 13.153 + sb.append("empty "); 13.154 + ElementKind ek = e.getKind(); 13.155 + switch (ek) { 13.156 + case CLASS: 13.157 + sb.append("clss"); 13.158 + break; 13.159 + case INTERFACE: 13.160 + sb.append("intf"); 13.161 + break; 13.162 + default: 13.163 + sb.append(ek); 13.164 + break; 13.165 + } 13.166 + sb.append(" "); 13.167 + Element encl = e.getEnclosingElement(); 13.168 + if (!isUnnamedPackage(encl) && encl.asType().getKind() != TypeKind.NONE) { 13.169 + sb.append("("); 13.170 + sb.append(asString(encl)); 13.171 + sb.append(")"); 13.172 + sb.append("."); 13.173 + } 13.174 + sb.append(e.getSimpleName()); 13.175 + if (e.asType().getKind() == TypeKind.ERROR) sb.append("!"); 13.176 + return sb.toString(); 13.177 + } 13.178 + }, null); 13.179 + } 13.180 + 13.181 + boolean isUnnamedPackage(Element e) { 13.182 + return (e != null && e.getKind() == ElementKind.PACKAGE 13.183 + && ((PackageElement) e).isUnnamed()); 13.184 + } 13.185 +} 13.186 + 13.187 + 13.188 +
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/Generator.java Wed Mar 02 21:13:55 2011 -0800 14.3 @@ -0,0 +1,111 @@ 14.4 +/* 14.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +import java.io.*; 14.28 +import java.util.*; 14.29 +import javax.annotation.processing.*; 14.30 +import javax.lang.model.element.*; 14.31 +import javax.lang.model.type.*; 14.32 +import javax.lang.model.util.*; 14.33 +import javax.tools.*; 14.34 + 14.35 +public class Generator extends JavacTestingAbstractProcessor { 14.36 + 14.37 + @Override 14.38 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 14.39 + for (TypeElement te: ElementFilter.typesIn(roundEnv.getRootElements())) { 14.40 + System.err.println(te); 14.41 + generateIfMissing(te.getSuperclass()); 14.42 + generateIfMissing(te.getInterfaces()); 14.43 + } 14.44 + return true; 14.45 + } 14.46 + 14.47 + void generateIfMissing(List<? extends TypeMirror> ts) { 14.48 + for (TypeMirror t: ts) 14.49 + generateIfMissing(t); 14.50 + } 14.51 + 14.52 + void generateIfMissing(TypeMirror t) { 14.53 + if (t == null) 14.54 + return; 14.55 + if (t.getKind() == TypeKind.ERROR) { 14.56 + Element e = ((ErrorType) t).asElement(); 14.57 + if (e == null) 14.58 + return; 14.59 + if (e.asType().getKind() == TypeKind.ERROR) 14.60 + createFile((TypeElement) e); 14.61 + } 14.62 + } 14.63 + 14.64 + void createFile(TypeElement e) { 14.65 + try { 14.66 + JavaFileObject fo = filer.createSourceFile(e.getSimpleName()); 14.67 + Writer out = fo.openWriter(); 14.68 + try { 14.69 + switch (e.getKind()) { 14.70 + case CLASS: 14.71 + out.write("import java.util.*;\n"); 14.72 + out.write("class " + signature(e) + " {\n"); 14.73 + out.write(" public void run() {\n"); 14.74 + out.write(" Class<?> c = getClass();\n"); 14.75 + out.write(" System.out.println(\"class: \" + c);\n"); 14.76 + out.write(" System.out.println(\"superclass: \" + c.getSuperclass());\n"); 14.77 + out.write(" System.out.println(\"generic superclass: \" +c.getGenericSuperclass());\n"); 14.78 + out.write(" System.out.println(\"interfaces: \" + Arrays.asList(c.getInterfaces()));\n"); 14.79 + out.write(" System.out.println(\"generic interfaces: \" + Arrays.asList(c.getGenericInterfaces()));\n"); 14.80 + out.write(" }\n"); 14.81 + out.write("}\n"); 14.82 + break; 14.83 + case INTERFACE: 14.84 + out.write("interface " + signature(e) + " {\n"); 14.85 + out.write(" void run();\n"); 14.86 + out.write("}\n"); 14.87 + break; 14.88 + } 14.89 + } finally { 14.90 + out.close(); 14.91 + } 14.92 + } catch (IOException ex) { 14.93 + messager.printMessage(Diagnostic.Kind.ERROR, "problem writing file: " + ex); 14.94 + } 14.95 + } 14.96 + 14.97 + String signature(TypeElement e) { 14.98 + System.err.println("signature: " + e + " " + e.getTypeParameters()); 14.99 + StringBuilder sb = new StringBuilder(); 14.100 + sb.append(e.getSimpleName()); 14.101 + if (!e.getTypeParameters().isEmpty()) { 14.102 + sb.append("<"); 14.103 + String sep = ""; 14.104 + for (TypeParameterElement t : e.getTypeParameters()) { 14.105 + sb.append(sep); 14.106 + sb.append(t); 14.107 + sep = ","; 14.108 + } 14.109 + sb.append(">"); 14.110 + } 14.111 + return sb.toString(); 14.112 + } 14.113 +} 14.114 +
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingClass.java Wed Mar 02 21:13:55 2011 -0800 15.3 @@ -0,0 +1,38 @@ 15.4 +/* 15.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/* 15.28 + * @test 15.29 + * @bug 6639645 15.30 + * @summary Modeling type implementing missing interfaces 15.31 + * @library ../../../../lib 15.32 + * @build JavacTestingAbstractProcessor Generator 15.33 + * @compile -XprintRounds -processor Generator TestMissingClass.java 15.34 + * @run main TestMissingClass 15.35 + */ 15.36 + 15.37 +public class TestMissingClass extends MissingClass { 15.38 + public static void main(String... args) { 15.39 + new TestMissingClass().run(); 15.40 + } 15.41 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericClass1.java Wed Mar 02 21:13:55 2011 -0800 16.3 @@ -0,0 +1,39 @@ 16.4 +/* 16.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +/* 16.28 + * @test 16.29 + * @bug 6639645 16.30 + * @summary Modeling type implementing missing interfaces 16.31 + * @library ../../../../lib 16.32 + * @clean MissingGenericClass1 16.33 + * @build JavacTestingAbstractProcessor Generator 16.34 + * @compile -XprintRounds -processor Generator TestMissingGenericClass1.java 16.35 + * @run main TestMissingGenericClass1 16.36 + */ 16.37 + 16.38 +public class TestMissingGenericClass1 extends MissingGenericClass1<String> { 16.39 + public static void main(String... args) { 16.40 + new TestMissingGenericClass1().run(); 16.41 + } 16.42 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericClass2.java Wed Mar 02 21:13:55 2011 -0800 17.3 @@ -0,0 +1,39 @@ 17.4 +/* 17.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +/* 17.28 + * @test 17.29 + * @bug 6639645 17.30 + * @summary Modeling type implementing missing interfaces 17.31 + * @library ../../../../lib 17.32 + * @clean MissingGenericClass2 17.33 + * @build JavacTestingAbstractProcessor Generator 17.34 + * @compile -XprintRounds -processor Generator TestMissingGenericClass2.java 17.35 + * @run main TestMissingGenericClass2 17.36 + */ 17.37 + 17.38 +public class TestMissingGenericClass2 extends MissingGenericClass2<String,Integer> { 17.39 + public static void main(String... args) { 17.40 + new TestMissingGenericClass2().run(); 17.41 + } 17.42 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericInterface1.java Wed Mar 02 21:13:55 2011 -0800 18.3 @@ -0,0 +1,52 @@ 18.4 +/* 18.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, asrm 18.10 + * published by the Free Software Foundation. 18.11 + * 18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.15 + * version 2 for more details (a copy is included in the LICENSE file that 18.16 + * accompanied this code). 18.17 + * 18.18 + * You should have received a copy of the GNU General Public License version 18.19 + * 2 along with this work; if not, write to the Free Software Foundation, 18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.21 + * 18.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.23 + * or visit www.oracle.com if you need additional information or have any 18.24 + * questions. 18.25 + */ 18.26 + 18.27 +/* 18.28 + * @test 18.29 + * @bug 6639645 18.30 + * @summary Modeling type implementing missing interfaces 18.31 + * @library ../../../../lib 18.32 + * @clean MissingGenericInterface1 18.33 + * @build JavacTestingAbstractProcessor Generator 18.34 + * @compile -XprintRounds -processor Generator TestMissingGenericInterface1.java 18.35 + * @run main TestMissingGenericInterface1 18.36 + */ 18.37 + 18.38 +import java.util.*; 18.39 + 18.40 +public class TestMissingGenericInterface1 implements MissingGenericInterface1<String> { 18.41 + public static void main(String... args) { 18.42 + new TestMissingGenericInterface1().run(); 18.43 + } 18.44 + 18.45 + @Override 18.46 + public void run() { 18.47 + Class<?> c = getClass(); 18.48 + System.out.println("class: " + c); 18.49 + System.out.println("superclass: " + c.getSuperclass()); 18.50 + System.out.println("generic superclass: " +c.getGenericSuperclass()); 18.51 + System.out.println("interfaces: " + Arrays.asList(c.getInterfaces())); 18.52 + System.out.println("generic interfaces: " + Arrays.asList(c.getGenericInterfaces())); 18.53 + } 18.54 + 18.55 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingGenericInterface2.java Wed Mar 02 21:13:55 2011 -0800 19.3 @@ -0,0 +1,52 @@ 19.4 +/* 19.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, asrm 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/* 19.28 + * @test 19.29 + * @bug 6639645 19.30 + * @summary Modeling type implementing missing interfaces 19.31 + * @library ../../../../lib 19.32 + * @clean MissingGenericInterface2 19.33 + * @build JavacTestingAbstractProcessor Generator 19.34 + * @compile -XprintRounds -processor Generator TestMissingGenericInterface2.java 19.35 + * @run main TestMissingGenericInterface2 19.36 + */ 19.37 + 19.38 +import java.util.*; 19.39 + 19.40 +public class TestMissingGenericInterface2 implements MissingGenericInterface2<Integer,String> { 19.41 + public static void main(String... args) { 19.42 + new TestMissingGenericInterface2().run(); 19.43 + } 19.44 + 19.45 + @Override 19.46 + public void run() { 19.47 + Class<?> c = getClass(); 19.48 + System.out.println("class: " + c); 19.49 + System.out.println("superclass: " + c.getSuperclass()); 19.50 + System.out.println("generic superclass: " +c.getGenericSuperclass()); 19.51 + System.out.println("interfaces: " + Arrays.asList(c.getInterfaces())); 19.52 + System.out.println("generic interfaces: " + Arrays.asList(c.getGenericInterfaces())); 19.53 + } 19.54 + 19.55 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement2/TestMissingInterface.java Wed Mar 02 21:13:55 2011 -0800 20.3 @@ -0,0 +1,51 @@ 20.4 +/* 20.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, asrm 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +/* 20.28 + * @test 20.29 + * @bug 6639645 20.30 + * @summary Modeling type implementing missing interfaces 20.31 + * @library ../../../../lib 20.32 + * @build JavacTestingAbstractProcessor Generator 20.33 + * @compile -XprintRounds -processor Generator TestMissingInterface.java 20.34 + * @run main TestMissingInterface 20.35 + */ 20.36 + 20.37 +import java.util.*; 20.38 + 20.39 +public class TestMissingInterface implements MissingInterface { 20.40 + public static void main(String... args) { 20.41 + new TestMissingInterface().run(); 20.42 + } 20.43 + 20.44 + @Override 20.45 + public void run() { 20.46 + Class<?> c = getClass(); 20.47 + System.out.println("class: " + c); 20.48 + System.out.println("superclass: " + c.getSuperclass()); 20.49 + System.out.println("generic superclass: " +c.getGenericSuperclass()); 20.50 + System.out.println("interfaces: " + Arrays.asList(c.getInterfaces())); 20.51 + System.out.println("generic interfaces: " + Arrays.asList(c.getGenericInterfaces())); 20.52 + } 20.53 + 20.54 +}