Java Code Examples for sun.reflect.generics.visitor.Reifier#getResult()

The following examples show how to use sun.reflect.generics.visitor.Reifier#getResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericDeclRepository.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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++) {
            Reifier r = getReifier(); // obtain visitor
            ftps[i].accept(r); // reify subtree
            // extract result from visitor and store it
            typeParams[i] = (TypeVariable<?>) r.getResult();
        }
        this.typeParams = typeParams; // cache overall result
    }
    return typeParams.clone(); // return cached result
}
 
Example 2
Source File: ConstructorRepository.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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++) {
            Reifier r = getReifier(); // obtain visitor
            ets[i].accept(r); // reify subtree
            // extract result from visitor and store it
            es[i] = r.getResult();
        }
        exceptionTypes = es; // cache overall result
    }
    return exceptionTypes.clone(); // return cached result
}
 
Example 3
Source File: ClassRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public Type[] getSuperInterfaces(){
    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)
        Type[] sis = new Type[ts.length];
        // reify all subtrees
        for (int i = 0; i < ts.length; i++) {
            Reifier r = getReifier(); // obtain visitor
            ts[i].accept(r);// reify subtree
            // extract result from visitor and store it
            sis[i] = r.getResult();
        }
        superInterfaces = sis; // cache overall result
    }
    return superInterfaces.clone(); // return cached result
}
 
Example 4
Source File: GenericDeclRepository.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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++) {
            Reifier r = getReifier(); // obtain visitor
            ftps[i].accept(r); // reify subtree
            // extract result from visitor and store it
            typeParams[i] = (TypeVariable<?>) r.getResult();
        }
        this.typeParams = typeParams; // cache overall result
    }
    return typeParams.clone(); // return cached result
}
 
Example 5
Source File: GenericDeclRepository.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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++) {
            Reifier r = getReifier(); // obtain visitor
            ftps[i].accept(r); // reify subtree
            // extract result from visitor and store it
            typeParams[i] = (TypeVariable<?>) r.getResult();
        }
        this.typeParams = typeParams; // cache overall result
    }
    return typeParams.clone(); // return cached result
}
 
Example 6
Source File: ConstructorRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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++) {
            Reifier r = getReifier(); // obtain visitor
            ets[i].accept(r); // reify subtree
            // extract result from visitor and store it
            es[i] = r.getResult();
        }
        exceptionTypes = es; // cache overall result
    }
    return exceptionTypes.clone(); // return cached result
}
 
Example 7
Source File: FieldRepository.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Type getGenericType(){
    if (genericType == null) { // lazily initialize generic type
        Reifier r = getReifier(); // obtain visitor
        getTree().accept(r); // reify subtree
        // extract result from visitor and cache it
        genericType = r.getResult();
    }
    return genericType; // return cached result
}
 
Example 8
Source File: FieldRepository.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type getGenericType(){
    if (genericType == null) { // lazily initialize generic type
        Reifier r = getReifier(); // obtain visitor
        getTree().accept(r); // reify subtree
        // extract result from visitor and cache it
        genericType = r.getResult();
    }
    return genericType; // return cached result
}
 
Example 9
Source File: ClassRepository.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type getSuperclass() {
    Type superclass = this.superclass;
    if (superclass == null) { // lazily initialize superclass
        Reifier r = getReifier(); // obtain visitor
        // 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 superclass; // return cached result
}
 
Example 10
Source File: MethodRepository.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type getReturnType() {
    if (returnType == null) { // lazily initialize return type
        Reifier r = getReifier(); // obtain visitor
        // Extract return type subtree from AST and reify
        getTree().getReturnType().accept(r);
        // extract result from visitor and cache it
        returnType = r.getResult();
        }
    return returnType; // return cached result
}
 
Example 11
Source File: ConstructorRepository.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private Type[] computeExceptionTypes() {
    // first, extract exception type subtree(s) from AST
    FieldTypeSignature[] ets = getTree().getExceptionTypes();
    // create array to store reified subtree(s)
    int length = ets.length;
    Type[] exceptionTypes = new Type[length];
    // reify all subtrees
    for (int i = 0; i < length; i++) {
        Reifier r = getReifier(); // obtain visitor
        ets[i].accept(r); // reify subtree
        // extract result from visitor and store it
        exceptionTypes[i] = r.getResult();
    }
    return exceptionTypes;
}
 
Example 12
Source File: AnnotationParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: ClassRepository.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public Type getSuperclass(){
    if (superclass == null) { // lazily initialize superclass
        Reifier r = getReifier(); // obtain visitor
        // Extract superclass subtree from AST and reify
        getTree().getSuperclass().accept(r);
        // extract result from visitor and cache it
        superclass = r.getResult();
        }
    return superclass; // return cached result
}
 
Example 14
Source File: MethodRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public Type getReturnType() {
    if (returnType == null) { // lazily initialize return type
        Reifier r = getReifier(); // obtain visitor
        // Extract return type subtree from AST and reify
        getTree().getReturnType().accept(r);
        // extract result from visitor and cache it
        returnType = r.getResult();
        }
    return returnType; // return cached result
}
 
Example 15
Source File: LazyReflectiveObjectGenerator.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
Type[] reifyBounds(FieldTypeSignature[] boundASTs) {
    final int length = boundASTs.length;
    final Type[] bounds = new Type[length];
    // iterate over bound trees, reifying each in turn
    for (int i = 0; i < length; i++) {
        Reifier r = getReifier();
        boundASTs[i].accept(r);
        bounds[i] = r.getResult();
    }
    return bounds;
}
 
Example 16
Source File: GenericDeclRepository.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private TypeVariable<?>[] computeTypeParameters() {
    // first, extract type parameter subtree(s) from AST
    FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
    // create array to store reified subtree(s)
    int length = ftps.length;
    TypeVariable<?>[] typeParameters = new TypeVariable<?>[length];
    // reify all subtrees
    for (int i = 0; i < length; i++) {
        Reifier r = getReifier(); // obtain visitor
        ftps[i].accept(r); // reify subtree
        // extract result from visitor and store it
        typeParameters[i] = (TypeVariable<?>) r.getResult();
    }
    return typeParameters;
}
 
Example 17
Source File: AnnotationParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 18
Source File: WildcardTypeImpl.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
        FieldTypeSignature[] fts = getUpperBoundASTs(); // get AST

        // 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 upperBounds.clone(); // return cached bounds
}
 
Example 19
Source File: TypeVariableImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        FieldTypeSignature[] fts = getBoundASTs(); // get AST
        // 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 bounds.clone(); // return cached bounds
}
 
Example 20
Source File: TypeVariableImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        FieldTypeSignature[] fts = getBoundASTs(); // get AST
        // 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 bounds.clone(); // return cached bounds
}