< prev index next >

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

Print this page
rev 12608 : [mq]: XXXXXXX-gt-lt-in-code


  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();
 101             if (name == null) {
 102                 return null;
 103             }
 104         }
 105         return name;
 106     }
 107 
 108     public MethodType getMethodOrFieldType() {
 109         if (isInvocable())
 110             return getMethodType();
 111         if (isGetter())
 112             return MethodType.methodType(getFieldType());
 113         if (isSetter())
 114             return MethodType.methodType(void.class, getFieldType());
 115         throw new InternalError("not a method or field: "+this);
 116     }


 710         if (this == that)  return true;
 711         if (that == null)  return false;
 712         return this.clazz == that.clazz
 713                 && this.getReferenceKind() == that.getReferenceKind()
 714                 && Objects.equals(this.name, that.name)
 715                 && Objects.equals(this.getType(), that.getType());
 716     }
 717 
 718     // Construction from symbolic parts, for queries:
 719     /** Create a field or type name from the given components:
 720      *  Declaring class, name, type, reference kind.
 721      *  The declaring class may be supplied as null if this is to be a bare name and type.
 722      *  The resulting name will in an unresolved state.
 723      */
 724     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 725         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 726         initResolved(false);
 727     }
 728     /** Create a method or constructor name from the given components:
 729      *  Declaring class, name, type, reference kind.
 730      *  It will be a constructor if and only if the name is {@code "&lt;init&gt;"}.
 731      *  The declaring class may be supplied as null if this is to be a bare name and type.
 732      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 733      *  The resulting name will in an unresolved state.
 734      */
 735     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 736         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
 737         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 738         initResolved(false);
 739     }
 740     /** Create a method, constructor, or field name from the given components:
 741      *  Reference kind, declaring class, name, type.
 742      */
 743     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 744         int kindFlags;
 745         if (MethodHandleNatives.refKindIsField(refKind)) {
 746             kindFlags = IS_FIELD;
 747             if (!(type instanceof Class))
 748                 throw newIllegalArgumentException("not a field type");
 749         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
 750             kindFlags = IS_METHOD;




  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 "<init>"}.
  97      */
  98     public String getName() {
  99         if (name == null) {
 100             expandFromVM();
 101             if (name == null) {
 102                 return null;
 103             }
 104         }
 105         return name;
 106     }
 107 
 108     public MethodType getMethodOrFieldType() {
 109         if (isInvocable())
 110             return getMethodType();
 111         if (isGetter())
 112             return MethodType.methodType(getFieldType());
 113         if (isSetter())
 114             return MethodType.methodType(void.class, getFieldType());
 115         throw new InternalError("not a method or field: "+this);
 116     }


 710         if (this == that)  return true;
 711         if (that == null)  return false;
 712         return this.clazz == that.clazz
 713                 && this.getReferenceKind() == that.getReferenceKind()
 714                 && Objects.equals(this.name, that.name)
 715                 && Objects.equals(this.getType(), that.getType());
 716     }
 717 
 718     // Construction from symbolic parts, for queries:
 719     /** Create a field or type name from the given components:
 720      *  Declaring class, name, type, reference kind.
 721      *  The declaring class may be supplied as null if this is to be a bare name and type.
 722      *  The resulting name will in an unresolved state.
 723      */
 724     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 725         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 726         initResolved(false);
 727     }
 728     /** Create a method or constructor name from the given components:
 729      *  Declaring class, name, type, reference kind.
 730      *  It will be a constructor if and only if the name is {@code "<init>"}.
 731      *  The declaring class may be supplied as null if this is to be a bare name and type.
 732      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 733      *  The resulting name will in an unresolved state.
 734      */
 735     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 736         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
 737         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 738         initResolved(false);
 739     }
 740     /** Create a method, constructor, or field name from the given components:
 741      *  Reference kind, declaring class, name, type.
 742      */
 743     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 744         int kindFlags;
 745         if (MethodHandleNatives.refKindIsField(refKind)) {
 746             kindFlags = IS_FIELD;
 747             if (!(type instanceof Class))
 748                 throw newIllegalArgumentException("not a field type");
 749         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
 750             kindFlags = IS_METHOD;


< prev index next >