Search in sources :

Example 6 with Reifier

use of sun.reflect.generics.visitor.Reifier in project jdk8u_jdk by JetBrains.

the class ClassRepository method getSuperInterfaces.

public Type[] getSuperInterfaces() {
    Type[] superInterfaces = this.superInterfaces;
    if (superInterfaces == null) {
        // lazily initialize super interfaces
        // first, extract super interface subtree(s) from AST
        TypeTree[] ts = getTree().getSuperInterfaces();
        // create array to store reified subtree(s)
        superInterfaces = new Type[ts.length];
        // reify all subtrees
        for (int i = 0; i < ts.length; i++) {
            // obtain visitor
            Reifier r = getReifier();
            // reify subtree
            ts[i].accept(r);
            // extract result from visitor and store it
            superInterfaces[i] = r.getResult();
        }
        this.superInterfaces = superInterfaces;
    }
    // return cached result
    return superInterfaces.clone();
}
Also used : Type(java.lang.reflect.Type) TypeTree(sun.reflect.generics.tree.TypeTree) Reifier(sun.reflect.generics.visitor.Reifier)

Example 7 with Reifier

use of sun.reflect.generics.visitor.Reifier in project jdk8u_jdk by JetBrains.

the class MethodRepository method getReturnType.

// public API
public Type getReturnType() {
    if (returnType == null) {
        // lazily initialize return type
        // obtain visitor
        Reifier r = getReifier();
        // Extract return type subtree from AST and reify
        getTree().getReturnType().accept(r);
        // extract result from visitor and cache it
        returnType = r.getResult();
    }
    // return cached result
    return returnType;
}
Also used : Reifier(sun.reflect.generics.visitor.Reifier)

Example 8 with Reifier

use of sun.reflect.generics.visitor.Reifier in project jdk8u_jdk by JetBrains.

the class ClassRepository method getSuperclass.

// 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 getSuperclass() {
    Type superclass = this.superclass;
    if (superclass == null) {
        // lazily initialize superclass
        // obtain visitor
        Reifier r = getReifier();
        // Extract superclass subtree from AST and reify
        getTree().getSuperclass().accept(r);
        // extract result from visitor and cache it
        superclass = r.getResult();
        this.superclass = superclass;
    }
    // return cached result
    return superclass;
}
Also used : Type(java.lang.reflect.Type) Reifier(sun.reflect.generics.visitor.Reifier)

Example 9 with Reifier

use of sun.reflect.generics.visitor.Reifier 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)

Example 10 with Reifier

use of sun.reflect.generics.visitor.Reifier in project jdk8u_jdk by JetBrains.

the class ConstructorRepository method getExceptionTypes.

public Type[] getExceptionTypes() {
    if (exceptionTypes == null) {
        // lazily initialize exception types
        // first, extract exception type subtree(s) from AST
        FieldTypeSignature[] ets = getTree().getExceptionTypes();
        // create array to store reified subtree(s)
        Type[] es = new Type[ets.length];
        // reify all subtrees
        for (int i = 0; i < ets.length; i++) {
            // obtain visitor
            Reifier r = getReifier();
            // reify subtree
            ets[i].accept(r);
            // extract result from visitor and store it
            es[i] = r.getResult();
        }
        // cache overall result
        exceptionTypes = es;
    }
    // return cached result
    return exceptionTypes.clone();
}
Also used : Type(java.lang.reflect.Type) Reifier(sun.reflect.generics.visitor.Reifier) FieldTypeSignature(sun.reflect.generics.tree.FieldTypeSignature)

Aggregations

Reifier (sun.reflect.generics.visitor.Reifier)11 Type (java.lang.reflect.Type)7 FieldTypeSignature (sun.reflect.generics.tree.FieldTypeSignature)5 WildcardType (java.lang.reflect.WildcardType)2 TypeSignature (sun.reflect.generics.tree.TypeSignature)2 AnnotatedType (java.lang.reflect.AnnotatedType)1 TypeVariable (java.lang.reflect.TypeVariable)1 AnnotationType (sun.reflect.annotation.AnnotationType)1 GenericsFactory (sun.reflect.generics.factory.GenericsFactory)1 SignatureParser (sun.reflect.generics.parser.SignatureParser)1 FormalTypeParameter (sun.reflect.generics.tree.FormalTypeParameter)1 MethodTypeSignature (sun.reflect.generics.tree.MethodTypeSignature)1 TypeTree (sun.reflect.generics.tree.TypeTree)1