Search in sources :

Example 1 with TypeSignature

use of sun.reflect.generics.tree.TypeSignature in project jdk8u_jdk by JetBrains.

the class ConstructorRepository method getParameterTypes.

// public API
/*
 * When queried for a particular piece of type information, the
 * general pattern is to consult the corresponding cached value.
 * If the corresponding field is non-null, it is returned.
 * If not, it is created lazily. This is done by selecting the appropriate
 * part of the tree and transforming it into a reflective object
 * using a visitor.
 * a visitor, which is created by feeding it the factory
 * with which the repository was created.
 */
public Type[] getParameterTypes() {
    if (paramTypes == null) {
        // lazily initialize parameter types
        // first, extract parameter type subtree(s) from AST
        TypeSignature[] pts = getTree().getParameterTypes();
        // create array to store reified subtree(s)
        Type[] ps = new Type[pts.length];
        // reify all subtrees
        for (int i = 0; i < pts.length; i++) {
            // obtain visitor
            Reifier r = getReifier();
            // reify subtree
            pts[i].accept(r);
            // extract result from visitor and store it
            ps[i] = r.getResult();
        }
        // cache overall result
        paramTypes = ps;
    }
    // return cached result
    return paramTypes.clone();
}
Also used : TypeSignature(sun.reflect.generics.tree.TypeSignature) MethodTypeSignature(sun.reflect.generics.tree.MethodTypeSignature) FieldTypeSignature(sun.reflect.generics.tree.FieldTypeSignature) Type(java.lang.reflect.Type) Reifier(sun.reflect.generics.visitor.Reifier)

Example 2 with TypeSignature

use of sun.reflect.generics.tree.TypeSignature in project jdk8u_jdk by JetBrains.

the class AnnotationParser method parseSig.

private static Class<?> parseSig(String sig, Class<?> container) {
    if (sig.equals("V"))
        return void.class;
    SignatureParser parser = SignatureParser.make();
    TypeSignature typeSig = parser.parseTypeSig(sig);
    GenericsFactory factory = CoreReflectionFactory.make(container, ClassScope.make(container));
    Reifier reify = Reifier.make(factory);
    typeSig.accept(reify);
    Type result = reify.getResult();
    return toClass(result);
}
Also used : TypeSignature(sun.reflect.generics.tree.TypeSignature) Reifier(sun.reflect.generics.visitor.Reifier) GenericsFactory(sun.reflect.generics.factory.GenericsFactory) SignatureParser(sun.reflect.generics.parser.SignatureParser)

Aggregations

TypeSignature (sun.reflect.generics.tree.TypeSignature)2 Reifier (sun.reflect.generics.visitor.Reifier)2 Type (java.lang.reflect.Type)1 GenericsFactory (sun.reflect.generics.factory.GenericsFactory)1 SignatureParser (sun.reflect.generics.parser.SignatureParser)1 FieldTypeSignature (sun.reflect.generics.tree.FieldTypeSignature)1 MethodTypeSignature (sun.reflect.generics.tree.MethodTypeSignature)1