33 import sun.reflect.generics.factory.*;
34
35
36
37 /**
38 * Visitor that converts AST to reified types.
39 */
40 public class Reifier implements TypeTreeVisitor<Type> {
41 private Type resultType;
42 private final GenericsFactory factory;
43
44 private Reifier(GenericsFactory f){
45 factory = f;
46 }
47
48 private GenericsFactory getFactory(){ return factory;}
49
50 /**
51 * Factory method. The resulting visitor will convert an AST
52 * representing generic signatures into corresponding reflective
53 * objects, using the provided factory, <tt>f</tt>.
54 * @param f - a factory that can be used to manufacture reflective
55 * objects returned by this visitor
56 * @return A visitor that can be used to reify ASTs representing
57 * generic type information into reflective objects
58 */
59 public static Reifier make(GenericsFactory f){
60 return new Reifier(f);
61 }
62
63 // Helper method. Visits an array of TypeArgument and produces
64 // reified Type array.
65 private Type[] reifyTypeArguments(TypeArgument[] tas) {
66 Type[] ts = new Type[tas.length];
67 for (int i = 0; i < tas.length; i++) {
68 tas[i].accept(this);
69 ts[i] = resultType;
70 }
71 return ts;
72 }
73
|
33 import sun.reflect.generics.factory.*;
34
35
36
37 /**
38 * Visitor that converts AST to reified types.
39 */
40 public class Reifier implements TypeTreeVisitor<Type> {
41 private Type resultType;
42 private final GenericsFactory factory;
43
44 private Reifier(GenericsFactory f){
45 factory = f;
46 }
47
48 private GenericsFactory getFactory(){ return factory;}
49
50 /**
51 * Factory method. The resulting visitor will convert an AST
52 * representing generic signatures into corresponding reflective
53 * objects, using the provided factory, {@code f}.
54 * @param f - a factory that can be used to manufacture reflective
55 * objects returned by this visitor
56 * @return A visitor that can be used to reify ASTs representing
57 * generic type information into reflective objects
58 */
59 public static Reifier make(GenericsFactory f){
60 return new Reifier(f);
61 }
62
63 // Helper method. Visits an array of TypeArgument and produces
64 // reified Type array.
65 private Type[] reifyTypeArguments(TypeArgument[] tas) {
66 Type[] ts = new Type[tas.length];
67 for (int i = 0; i < tas.length; i++) {
68 tas[i].accept(this);
69 ts[i] = resultType;
70 }
71 return ts;
72 }
73
|