< prev index next >

jdk/src/java.base/share/classes/java/lang/invoke/MemberName.java

Print this page




  61  * When resolved, a member name's internal implementation may include references to JVM metadata.
  62  * This representation is stateless and only descriptive.
  63  * It provides no private information and no capability to use the member.
  64  * <p>
  65  * By contrast, a {@linkplain java.lang.reflect.Method} contains fuller information
  66  * about the internals of a method (except its bytecodes) and also
  67  * allows invocation.  A MemberName is much lighter than a Method,
  68  * since it contains about 7 fields to the 16 of Method (plus its sub-arrays),
  69  * and those seven fields omit much of the information in Method.
  70  * @author jrose
  71  */
  72 /*non-public*/ final class MemberName implements Member, Cloneable {
  73     private Class<?> clazz;       // class in which the method is defined
  74     private String   name;        // may be null if not yet materialized
  75     private Object   type;        // may be null if not yet materialized
  76     private int      flags;       // modifier bits; see reflect.Modifier
  77     //@Injected JVM_Method* vmtarget;
  78     //@Injected int         vmindex;
  79     private Object   resolution;  // if null, this guy is resolved
  80 


















  81     /** Return the declaring class of this member.
  82      *  In the case of a bare name and type, the declaring class will be null.
  83      */
  84     public Class<?> getDeclaringClass() {
  85         return clazz;
  86     }
  87 
  88     /** Utility method producing the class loader of the declaring class. */
  89     public ClassLoader getClassLoader() {
  90         return clazz.getClassLoader();
  91     }
  92 
  93     /** Return the simple name of this member.
  94      *  For a type, it is the same as {@link Class#getSimpleName}.
  95      *  For a method or field, it is the simple name of the member.
  96      *  For a constructor, it is always {@code "&lt;init&gt;"}.
  97      */
  98     public String getName() {
  99         if (name == null) {
 100             expandFromVM();




  61  * When resolved, a member name's internal implementation may include references to JVM metadata.
  62  * This representation is stateless and only descriptive.
  63  * It provides no private information and no capability to use the member.
  64  * <p>
  65  * By contrast, a {@linkplain java.lang.reflect.Method} contains fuller information
  66  * about the internals of a method (except its bytecodes) and also
  67  * allows invocation.  A MemberName is much lighter than a Method,
  68  * since it contains about 7 fields to the 16 of Method (plus its sub-arrays),
  69  * and those seven fields omit much of the information in Method.
  70  * @author jrose
  71  */
  72 /*non-public*/ final class MemberName implements Member, Cloneable {
  73     private Class<?> clazz;       // class in which the method is defined
  74     private String   name;        // may be null if not yet materialized
  75     private Object   type;        // may be null if not yet materialized
  76     private int      flags;       // modifier bits; see reflect.Modifier
  77     //@Injected JVM_Method* vmtarget;
  78     //@Injected int         vmindex;
  79     private Object   resolution;  // if null, this guy is resolved
  80 
  81 
  82     // The JVM uses values of -2 and above for vtable indexes.
  83     // Field values are simple positive offsets.
  84     // Ref: src/share/vm/oops/methodOop.hpp
  85     // This value is negative enough to avoid such numbers,
  86     // but not too negative.
  87     static final int
  88         MN_IS_METHOD           = 0x00010000, // method (not constructor)
  89         MN_IS_CONSTRUCTOR      = 0x00020000, // constructor
  90         MN_IS_FIELD            = 0x00040000, // field
  91         MN_IS_TYPE             = 0x00080000, // nested type
  92         MN_CALLER_SENSITIVE    = 0x00100000, // @CallerSensitive annotation detected
  93         MN_REFERENCE_KIND_SHIFT = 24, // refKind
  94         MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
  95         // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
  96         MN_SEARCH_SUPERCLASSES = 0x00100000,
  97         MN_SEARCH_INTERFACES   = 0x00200000;
  98 
  99     /** Return the declaring class of this member.
 100      *  In the case of a bare name and type, the declaring class will be null.
 101      */
 102     public Class<?> getDeclaringClass() {
 103         return clazz;
 104     }
 105 
 106     /** Utility method producing the class loader of the declaring class. */
 107     public ClassLoader getClassLoader() {
 108         return clazz.getClassLoader();
 109     }
 110 
 111     /** Return the simple name of this member.
 112      *  For a type, it is the same as {@link Class#getSimpleName}.
 113      *  For a method or field, it is the simple name of the member.
 114      *  For a constructor, it is always {@code "&lt;init&gt;"}.
 115      */
 116     public String getName() {
 117         if (name == null) {
 118             expandFromVM();


< prev index next >