< prev index next >

src/java.base/share/classes/sun/reflect/generics/repository/MethodRepository.java

Print this page




  36  * This class represents the generic type information for a method.
  37  * The code is not dependent on a particular reflective implementation.
  38  * It is designed to be used unchanged by at least core reflection and JDI.
  39  */
  40 public class MethodRepository extends ConstructorRepository {
  41 
  42     /** The generic return type info.  Lazily initialized. */
  43     private volatile Type returnType;
  44 
  45  // private, to enforce use of static factory
  46     private MethodRepository(String rawSig, GenericsFactory f) {
  47       super(rawSig, f);
  48     }
  49 
  50     /**
  51      * Static factory method.
  52      * @param rawSig - the generic signature of the reflective object
  53      * that this repository is servicing
  54      * @param f - a factory that will provide instances of reflective
  55      * objects when this repository converts its AST
  56      * @return a <tt>MethodRepository</tt> that manages the generic type
  57      * information represented in the signature <tt>rawSig</tt>
  58      */
  59     public static MethodRepository make(String rawSig, GenericsFactory f) {
  60         return new MethodRepository(rawSig, f);
  61     }
  62 
  63     public Type getReturnType() {
  64         Type value = returnType;
  65         if (value == null) {
  66             value = computeReturnType();
  67             returnType = value;
  68         }
  69         return value;
  70     }
  71 
  72     private Type computeReturnType() {
  73         Reifier r = getReifier(); // obtain visitor
  74         // Extract return type subtree from AST and reify
  75         getTree().getReturnType().accept(r);
  76         // extract result from visitor and cache it
  77         return r.getResult();


  36  * This class represents the generic type information for a method.
  37  * The code is not dependent on a particular reflective implementation.
  38  * It is designed to be used unchanged by at least core reflection and JDI.
  39  */
  40 public class MethodRepository extends ConstructorRepository {
  41 
  42     /** The generic return type info.  Lazily initialized. */
  43     private volatile Type returnType;
  44 
  45  // private, to enforce use of static factory
  46     private MethodRepository(String rawSig, GenericsFactory f) {
  47       super(rawSig, f);
  48     }
  49 
  50     /**
  51      * Static factory method.
  52      * @param rawSig - the generic signature of the reflective object
  53      * that this repository is servicing
  54      * @param f - a factory that will provide instances of reflective
  55      * objects when this repository converts its AST
  56      * @return a {@code MethodRepository} that manages the generic type
  57      * information represented in the signature {@code rawSig}
  58      */
  59     public static MethodRepository make(String rawSig, GenericsFactory f) {
  60         return new MethodRepository(rawSig, f);
  61     }
  62 
  63     public Type getReturnType() {
  64         Type value = returnType;
  65         if (value == null) {
  66             value = computeReturnType();
  67             returnType = value;
  68         }
  69         return value;
  70     }
  71 
  72     private Type computeReturnType() {
  73         Reifier r = getReifier(); // obtain visitor
  74         // Extract return type subtree from AST and reify
  75         getTree().getReturnType().accept(r);
  76         // extract result from visitor and cache it
  77         return r.getResult();
< prev index next >