feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.Tree;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract superclass for representing the generic type information for
|
||||
* a reflective entity.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public abstract class AbstractRepository<T extends Tree> {
|
||||
|
||||
// A factory used to produce reflective objects. Provided when the
|
||||
//repository is created. Will vary across implementations.
|
||||
private final GenericsFactory factory;
|
||||
|
||||
private final T tree; // the AST for the generic type info
|
||||
|
||||
//accessors
|
||||
private GenericsFactory getFactory() { return factory;}
|
||||
|
||||
/**
|
||||
* Accessor for <tt>tree</tt>.
|
||||
* @return the cached AST this repository holds
|
||||
*/
|
||||
protected T getTree(){ return tree;}
|
||||
|
||||
/**
|
||||
* Returns a <tt>Reifier</tt> used to convert parts of the
|
||||
* AST into reflective objects.
|
||||
* @return a <tt>Reifier</tt> used to convert parts of the
|
||||
* AST into reflective objects
|
||||
*/
|
||||
protected Reifier getReifier(){return Reifier.make(getFactory());}
|
||||
|
||||
/**
|
||||
* Constructor. Should only be used by subclasses. Concrete subclasses
|
||||
* should make their constructors private and provide public factory
|
||||
* methods.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
*/
|
||||
protected AbstractRepository(String rawSig, GenericsFactory f) {
|
||||
tree = parse(rawSig);
|
||||
factory = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AST for the genric type info of this entity.
|
||||
* @param s - a string representing the generic signature of this
|
||||
* entity
|
||||
* @return the AST for the generic type info of this entity.
|
||||
*/
|
||||
protected abstract T parse(String s);
|
||||
}
|
||||
116
jdkSrc/jdk8/sun/reflect/generics/repository/ClassRepository.java
Normal file
116
jdkSrc/jdk8/sun/reflect/generics/repository/ClassRepository.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.ClassSignature;
|
||||
import sun.reflect.generics.tree.TypeTree;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
import sun.reflect.generics.parser.SignatureParser;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a class.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class ClassRepository extends GenericDeclRepository<ClassSignature> {
|
||||
|
||||
public static final ClassRepository NONE = ClassRepository.make("Ljava/lang/Object;", null);
|
||||
|
||||
/** The generic superclass info. Lazily initialized. */
|
||||
private volatile Type superclass;
|
||||
|
||||
/** The generic superinterface info. Lazily initialized. */
|
||||
private volatile Type[] superInterfaces;
|
||||
|
||||
// private, to enforce use of static factory
|
||||
private ClassRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
protected ClassSignature parse(String s) {
|
||||
return SignatureParser.make().parseClassSig(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a <tt>ClassRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static ClassRepository make(String rawSig, GenericsFactory f) {
|
||||
return new ClassRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
}
|
||||
|
||||
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++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ts[i].accept(r);// reify subtree
|
||||
// extract result from visitor and store it
|
||||
superInterfaces[i] = r.getResult();
|
||||
}
|
||||
this.superInterfaces = superInterfaces;
|
||||
}
|
||||
return superInterfaces.clone(); // return cached result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.parser.SignatureParser;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.tree.MethodTypeSignature;
|
||||
import sun.reflect.generics.tree.TypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a constructor.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class ConstructorRepository
|
||||
extends GenericDeclRepository<MethodTypeSignature> {
|
||||
|
||||
private Type[] paramTypes; // caches the generic parameter types info
|
||||
private Type[] exceptionTypes; // caches the generic exception types info
|
||||
|
||||
// protected, to enforce use of static factory yet allow subclassing
|
||||
protected ConstructorRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
protected MethodTypeSignature parse(String s) {
|
||||
return SignatureParser.make().parseMethodSig(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a <tt>ConstructorRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static ConstructorRepository make(String rawSig,
|
||||
GenericsFactory f) {
|
||||
return new ConstructorRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// 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++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
pts[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
ps[i] = r.getResult();
|
||||
}
|
||||
paramTypes = ps; // cache overall result
|
||||
}
|
||||
return paramTypes.clone(); // return cached result
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.TypeSignature;
|
||||
import sun.reflect.generics.parser.SignatureParser;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a constructor.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class FieldRepository extends AbstractRepository<TypeSignature> {
|
||||
|
||||
private Type genericType; // caches the generic type info
|
||||
|
||||
// protected, to enforce use of static factory yet allow subclassing
|
||||
protected FieldRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
protected TypeSignature parse(String s) {
|
||||
return SignatureParser.make().parseTypeSig(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a <tt>FieldRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static FieldRepository make(String rawSig,
|
||||
GenericsFactory f) {
|
||||
return new FieldRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FormalTypeParameter;
|
||||
import sun.reflect.generics.tree.Signature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a generic
|
||||
* declaration.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public abstract class GenericDeclRepository<S extends Signature>
|
||||
extends AbstractRepository<S> {
|
||||
|
||||
/** The formal type parameters. Lazily initialized. */
|
||||
private volatile TypeVariable<?>[] typeParams;
|
||||
|
||||
protected GenericDeclRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
// 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++) {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a method.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class MethodRepository extends ConstructorRepository {
|
||||
|
||||
private Type returnType; // caches the generic return type info
|
||||
|
||||
// private, to enforce use of static factory
|
||||
private MethodRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a <tt>MethodRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static MethodRepository make(String rawSig, GenericsFactory f) {
|
||||
return new MethodRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// public API
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user