Search in sources :

Example 1 with Reifier

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

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

the class FieldRepository method getGenericType.

// 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 getGenericType() {
    if (genericType == null) {
        // lazily initialize generic type
        // obtain visitor
        Reifier r = getReifier();
        // reify subtree
        getTree().accept(r);
        // extract result from visitor and cache it
        genericType = r.getResult();
    }
    // return cached result
    return genericType;
}
Also used : Reifier(sun.reflect.generics.visitor.Reifier)

Example 3 with Reifier

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

the class GenericDeclRepository method getTypeParameters.

// 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, which is created by feeding it the factory
 * with which the repository was created.
 */
/**
     * Return the formal type parameters of this generic declaration.
     * @return the formal type parameters of this generic declaration
     */
public TypeVariable<?>[] getTypeParameters() {
    TypeVariable<?>[] typeParams = this.typeParams;
    if (typeParams == null) {
        // lazily initialize type parameters
        // first, extract type parameter subtree(s) from AST
        FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
        // create array to store reified subtree(s)
        typeParams = new TypeVariable<?>[ftps.length];
        // reify all subtrees
        for (int i = 0; i < ftps.length; i++) {
            // obtain visitor
            Reifier r = getReifier();
            // reify subtree
            ftps[i].accept(r);
            // extract result from visitor and store it
            typeParams[i] = (TypeVariable<?>) r.getResult();
        }
        // cache overall result
        this.typeParams = typeParams;
    }
    // return cached result
    return typeParams.clone();
}
Also used : TypeVariable(java.lang.reflect.TypeVariable) Reifier(sun.reflect.generics.visitor.Reifier) FormalTypeParameter(sun.reflect.generics.tree.FormalTypeParameter)

Example 4 with Reifier

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

the class TypeVariableImpl method getBounds.

/**
     * Returns an array of <tt>Type</tt> objects representing the
     * upper bound(s) of this type variable.  Note that if no upper bound is
     * explicitly declared, the upper bound is <tt>Object</tt>.
     *
     * <p>For each upper bound B:
     * <ul>
     *  <li>if B is a parameterized type or a type variable, it is created,
     *  (see {@link #ParameterizedType} for the details of the creation
     *  process for parameterized types).
     *  <li>Otherwise, B is resolved.
     * </ul>
     *
     * @throws <tt>TypeNotPresentException</tt>  if any of the
     *     bounds refers to a non-existent type declaration
     * @throws <tt>MalformedParameterizedTypeException</tt> if any of the
     *     bounds refer to a parameterized type that cannot be instantiated
     *     for any reason
     * @return an array of Types representing the upper bound(s) of this
     *     type variable
    */
public Type[] getBounds() {
    // lazily initialize bounds if necessary
    if (bounds == null) {
        // get AST
        FieldTypeSignature[] fts = getBoundASTs();
        // allocate result array; note that
        // keeping ts and bounds separate helps with threads
        Type[] ts = new Type[fts.length];
        // iterate over bound trees, reifying each in turn
        for (int j = 0; j < fts.length; j++) {
            Reifier r = getReifier();
            fts[j].accept(r);
            ts[j] = r.getResult();
        }
        // cache result
        bounds = ts;
    // could throw away bound ASTs here; thread safety?
    }
    // return cached bounds
    return bounds.clone();
}
Also used : AnnotationType(sun.reflect.annotation.AnnotationType) AnnotatedType(java.lang.reflect.AnnotatedType) Type(java.lang.reflect.Type) Reifier(sun.reflect.generics.visitor.Reifier) FieldTypeSignature(sun.reflect.generics.tree.FieldTypeSignature)

Example 5 with Reifier

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

the class WildcardTypeImpl method getUpperBounds.

/**
     * Returns an array of <tt>Type</tt> objects representing the  upper
     * bound(s) of this type variable.  Note that if no upper bound is
     * explicitly declared, the upper bound is <tt>Object</tt>.
     *
     * <p>For each upper bound B :
     * <ul>
     *  <li>if B is a parameterized type or a type variable, it is created,
     *  (see {@link #ParameterizedType} for the details of the creation
     *  process for parameterized types).
     *  <li>Otherwise, B is resolved.
     * </ul>
     *
     * @return an array of Types representing the upper bound(s) of this
     *     type variable
     * @throws <tt>TypeNotPresentException</tt> if any of the
     *     bounds refers to a non-existent type declaration
     * @throws <tt>MalformedParameterizedTypeException</tt> if any of the
     *     bounds refer to a parameterized type that cannot be instantiated
     *     for any reason
     */
public Type[] getUpperBounds() {
    // lazily initialize bounds if necessary
    if (upperBounds == null) {
        // get AST
        FieldTypeSignature[] fts = getUpperBoundASTs();
        // allocate result array; note that
        // keeping ts and bounds separate helps with threads
        Type[] ts = new Type[fts.length];
        // iterate over bound trees, reifying each in turn
        for (int j = 0; j < fts.length; j++) {
            Reifier r = getReifier();
            fts[j].accept(r);
            ts[j] = r.getResult();
        }
        // cache result
        upperBounds = ts;
    // could throw away upper bound ASTs here; thread safety?
    }
    // return cached bounds
    return upperBounds.clone();
}
Also used : Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) 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