Search in sources :

Example 11 with Reifier

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

the class WildcardTypeImpl method getLowerBounds.

/**
     * Returns an array of <tt>Type</tt> objects representing the
     * lower bound(s) of this type variable.  Note that if no lower bound is
     * explicitly declared, the lower bound is the type of <tt>null</tt>.
     * In this case, a zero length array is returned.
     *
     * <p>For each lower 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 lower 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[] getLowerBounds() {
    // lazily initialize bounds if necessary
    if (lowerBounds == null) {
        // get AST
        FieldTypeSignature[] fts = getLowerBoundASTs();
        // 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
        lowerBounds = ts;
    // could throw away lower bound ASTs here; thread safety?
    }
    // return cached bounds
    return lowerBounds.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