use of sun.reflect.generics.tree.FormalTypeParameter 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();
}
Aggregations