883 884 885 /** Produce a string form of this member name. 886 * For types, it is simply the type's own string (as reported by {@code toString}). 887 * For fields, it is {@code "DeclaringClass.name/type"}. 888 * For methods and constructors, it is {@code "DeclaringClass.name(ptype...)rtype"}. 889 * If the declaring class is null, the prefix {@code "DeclaringClass."} is omitted. 890 * If the member is unresolved, a prefix {@code "*."} is prepended. 891 */ 892 @SuppressWarnings("LocalVariableHidesMemberVariable") 893 @Override 894 public String toString() { 895 if (isType()) 896 return type.toString(); // class java.lang.String 897 // else it is a field, method, or constructor 898 StringBuilder buf = new StringBuilder(); 899 if (getDeclaringClass() != null) { 900 buf.append(getName(clazz)); 901 buf.append('.'); 902 } 903 String name = getName(); 904 buf.append(name == null ? "*" : name); 905 Object type = getType(); 906 if (!isInvocable()) { 907 buf.append('/'); 908 buf.append(type == null ? "*" : getName(type)); 909 } else { 910 buf.append(type == null ? "(*)*" : getName(type)); 911 } 912 byte refKind = getReferenceKind(); 913 if (refKind != REF_NONE) { 914 buf.append('/'); 915 buf.append(MethodHandleNatives.refKindName(refKind)); 916 } 917 //buf.append("#").append(System.identityHashCode(this)); 918 return buf.toString(); 919 } 920 private static String getName(Object obj) { 921 if (obj instanceof Class<?>) 922 return ((Class<?>)obj).getName(); 923 return String.valueOf(obj); 924 } 925 | 883 884 885 /** Produce a string form of this member name. 886 * For types, it is simply the type's own string (as reported by {@code toString}). 887 * For fields, it is {@code "DeclaringClass.name/type"}. 888 * For methods and constructors, it is {@code "DeclaringClass.name(ptype...)rtype"}. 889 * If the declaring class is null, the prefix {@code "DeclaringClass."} is omitted. 890 * If the member is unresolved, a prefix {@code "*."} is prepended. 891 */ 892 @SuppressWarnings("LocalVariableHidesMemberVariable") 893 @Override 894 public String toString() { 895 if (isType()) 896 return type.toString(); // class java.lang.String 897 // else it is a field, method, or constructor 898 StringBuilder buf = new StringBuilder(); 899 if (getDeclaringClass() != null) { 900 buf.append(getName(clazz)); 901 buf.append('.'); 902 } 903 String name = this.name; // avoid expanding from VM 904 buf.append(name == null ? "*" : name); 905 Object type = this.type; // avoid expanding from VM 906 if (!isInvocable()) { 907 buf.append('/'); 908 buf.append(type == null ? "*" : getName(type)); 909 } else { 910 buf.append(type == null ? "(*)*" : getName(type)); 911 } 912 byte refKind = getReferenceKind(); 913 if (refKind != REF_NONE) { 914 buf.append('/'); 915 buf.append(MethodHandleNatives.refKindName(refKind)); 916 } 917 //buf.append("#").append(System.identityHashCode(this)); 918 return buf.toString(); 919 } 920 private static String getName(Object obj) { 921 if (obj instanceof Class<?>) 922 return ((Class<?>)obj).getName(); 923 return String.valueOf(obj); 924 } 925 |