3530N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 1193N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1193N/A * This code is free software; you can redistribute it and/or modify it 1193N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 1193N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 1193N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1193N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1193N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1193N/A * version 2 for more details (a copy is included in the LICENSE file that 1193N/A * You should have received a copy of the GNU General Public License version 1193N/A * 2 along with this work; if not, write to the Free Software Foundation, 1193N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 2431N/A * A {@code MemberName} is a compact symbolic datum which fully characterizes 2431N/A * a method or field reference. 2431N/A * A member name refers to a field, method, constructor, or member type. 2431N/A * Every member name has a simple name (a string) and a type (either a Class or MethodType). 2431N/A * A member name may also have a non-null declaring class, or it may be simply 2431N/A * A member name may also have non-zero modifier flags. 2431N/A * Finally, a member name may be either resolved or unresolved. 2431N/A * If it is resolved, the existence of the named 2431N/A * Whether resolved or not, a member name provides no access rights or 2431N/A * invocation capability to its possessor. It is merely a compact 2431N/A * representation of all symbolic information necessary to link to 2431N/A * and properly use the named member. 2431N/A * When resolved, a member name's internal implementation may include references to JVM metadata. 1193N/A * This representation is stateless and only decriptive. 1193N/A * It provides no private information and no capability to use the member. 2431N/A * By contrast, a {@linkplain java.lang.reflect.Method} contains fuller information 1193N/A * about the internals of a method (except its bytecodes) and also 2431N/A * allows invocation. A MemberName is much lighter than a Method, 2431N/A * since it contains about 7 fields to the 16 of Method (plus its sub-arrays), 1193N/A * and those seven fields omit much of the information in Method. 1193N/A private int flags;
// modifier bits; see reflect.Modifier 5459N/A //@Injected JVM_Method* vmtarget; 2431N/A /** Return the declaring class of this member. 2431N/A * In the case of a bare name and type, the declaring class will be null. 2431N/A /** Utility method producing the class loader of the declaring class. */ 2431N/A /** Return the simple name of this member. 2431N/A * For a type, it is the same as {@link Class#getSimpleName}. 2431N/A * For a method or field, it is the simple name of the member. 2431N/A * For a constructor, it is always {@code "<init>"}. 2431N/A /** Return the declared type of this member, which 2431N/A * must be a method or constructor. 2431N/A /** Return the actual type under which this method or constructor must be invoked. 2431N/A * For non-static methods or constructors, this is the type with a leading parameter, 2431N/A * a reference to declaring class. For static methods, it is the same as the declared type. 2431N/A /** Utility method producing the parameter types of the method type. */ 2431N/A /** Utility method producing the return type of the method type. */ 2431N/A /** Return the declared type of this member, which 2431N/A * If it is a type member, that type itself is returned. 2431N/A /** Utility method to produce either the method type or field type of this member. */ 2431N/A /** Utility method to produce the signature of this member, 2431N/A * used within the class file format to describe its type. 2431N/A /** Return the modifier flags of this member. 2431N/A * @see java.lang.reflect.Modifier 5459N/A /** Return the reference kind of this member, or zero if none. 5459N/A // Looking up an interface method, can get (e.g.) Object.hashCode 5459N/A // Looked up a virtual, can get (e.g.) final String.hashCode. 5459N/A// if (isConstructor() && refKind != REF_newInvokeSpecial) 5459N/A// flags += (IS_METHOD - IS_CONSTRUCTOR); 5459N/A// else if (refKind == REF_newInvokeSpecial && isMethod()) 5459N/A// flags += (IS_CONSTRUCTOR - IS_METHOD); 5459N/A /** Utility method to query if this member is a method handle invocation (invoke or invokeExact). */ 2431N/A /** Utility method to query the modifier flags of this member. */ 2431N/A /** Utility method to query the modifier flags of this member. */ 2431N/A /** Utility method to query the modifier flags of this member. */ 2431N/A /** Utility method to query the modifier flags of this member. */ 2431N/A /** Utility method to query the modifier flags of this member. */ 5459N/A /** Utility method to query whether this member or its defining class is final. */ 5459N/A /** Utility method to query the modifier flags of this member. */ 2431N/A /** Utility method to query the modifier flags of this member. */ 5459N/A /** Utility method to query the modifier flags of this member. */ 1193N/A // let the rest (native, volatile, transient, etc.) be tested via Modifier.isFoo 1193N/A // unofficial modifier flags, used by HotSpot: 2431N/A /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */ 2431N/A /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */ 2431N/A /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */ 1193N/A // modifiers exported by the JVM: 1193N/A // private flags, not part of RECOGNIZED_MODIFIERS: 2431N/A /** Utility method to query whether this member is a method or constructor. */ 2431N/A /** Utility method to query whether this member is a method, constructor, or field. */ 2431N/A /** Query whether this member is a method. */ 2431N/A /** Query whether this member is a constructor. */ 2431N/A /** Query whether this member is a field. */ 2431N/A /** Query whether this member is a type. */ 2431N/A /** Utility method to query whether this member is neither public, private, nor protected. */ 6338N/A /** Utility method to query whether this member is annotated with @CallerSensitive. */ 5459N/A /** Utility method to query whether this member is accessible from a given lookup class. */ 1193N/A /** Initialize a query. It is not resolved. */ 1193N/A // defining class is allowed to be null (for a naked name/type pair) 2431N/A //name.toString(); // null check 2431N/A //type.equals(type); // null check 5463N/A //assert(referenceKindIsConsistent()); // do this after resolution 1193N/A // Capturing information from the Core Reflection API: 2431N/A /** Create a name for the given reflected method. The resulting name will be in a resolved state. */ 1193N/A // fill in vmtarget, vmindex while we have m in hand: 2431N/A /** Create a name for the given reflected constructor. The resulting name will be in a resolved state. */ 1193N/A // fill in vmtarget, vmindex while we have ctor in hand: 5459N/A /** Create a name for the given reflected field. The resulting name will be in a resolved state. 1193N/A // fill in vmtarget, vmindex while we have fld in hand: 2431N/A /** Create a name for the given class. The resulting name will be in a resolved state. */ 1193N/A // bare-bones constructor; the JVM will fill it in 5459N/A /** Get the definition of this member name. 5459N/A * This may be in a super-class of the declaring class of this member. 5459N/A /** Decide if two member names have exactly the same symbolic content. 5459N/A * Does not take into account any actual class members, so even if 5459N/A * two member names resolve to the same actual member, they may 1193N/A // Construction from symbolic parts, for queries: 5459N/A /** Create a field or type name from the given components: Declaring class, name, type, reference kind. 2431N/A * The declaring class may be supplied as null if this is to be a bare name and type. 2431N/A * The resulting name will in an unresolved state. 2431N/A /** Create a field or type name from the given components: Declaring class, name, type. 2431N/A * The declaring class may be supplied as null if this is to be a bare name and type. 2431N/A * The modifier flags default to zero. 2431N/A * The resulting name will in an unresolved state. 2431N/A /** Create a method or constructor name from the given components: Declaring class, name, type, modifiers. 2431N/A * It will be a constructor if and only if the name is {@code "<init>"}. 2431N/A * The declaring class may be supplied as null if this is to be a bare name and type. 5459N/A * The last argument is optional, a boolean which requests REF_invokeSpecial. 2431N/A * The resulting name will in an unresolved state. 5459N/A// /** Create a method or constructor name from the given components: Declaring class, name, type, modifiers. 5459N/A// * It will be a constructor if and only if the name is {@code "<init>"}. 5459N/A// * The declaring class may be supplied as null if this is to be a bare name and type. 5459N/A// * The modifier flags default to zero. 5459N/A// * The resulting name will in an unresolved state. 5459N/A// public MemberName(Class<?> defClass, String name, MethodType type, Void unused) { 5459N/A// this(defClass, name, type, REF_NONE); 5459N/A /** Query whether this member name is resolved to a non-static, non-final method. 2431N/A /** Query whether this member name is resolved. 2431N/A * A resolved member name is one for which the JVM has found 2431N/A * a method, constructor, field, or type binding corresponding exactly to the name. 2431N/A /** Produce a string form of this member name. 2431N/A * For types, it is simply the type's own string (as reported by {@code toString}). 2431N/A * For methods and constructors, it is {@code "DeclaringClass.name(ptype...)rtype"}. 2431N/A * If the declaring class is null, the prefix {@code "DeclaringClass."} is omitted. 2431N/A * If the member is unresolved, a prefix {@code "*."} is prepended. 1193N/A // else it is a field, method, or constructor 5459N/A //buf.append("#").append(System.identityHashCode(this)); 4250N/A return "no such constructor";
1193N/A /** Actually making a query requires an access check. */ 2431N/A /** A factory type for resolving member names with the help of the VM. 2431N/A * TBD: Define access-safe public constructors for this factory. 2040N/A // JVM returned to us with an intentional overflow! 1193N/A // Signature matching is not the same as type matching, since 1193N/A // one signature might correspond to several types. 1193N/A // So if matchType is a Class or MethodType, refilter the results. 2431N/A /** Produce a resolved version of the given member. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * If lookup fails or access is not permitted, null is returned. 2431N/A * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. 5459N/A // JVM reports that the "bytecode behavior" would get an error 2431N/A /** Produce a resolved version of the given member. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 3530N/A * If lookup fails or access is not permitted, a {@linkplain ReflectiveOperationException} is thrown. 2431N/A * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. 5459N/A /** Produce a resolved version of the given member. 5459N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 5459N/A * Access checking is performed on behalf of the given {@code lookupClass}. 5459N/A * If lookup fails or access is not permitted, return null. 5459N/A * Otherwise a fresh copy of the given member is returned, with modifier bits filled in. 2431N/A /** Return a list of all methods defined by the given class. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * Inaccessible members are not added to the last. 2431N/A /** Return a list of matching methods defined by the given class. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Returned methods will match the name (if not null) and the type (if not null). 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * Inaccessible members are not added to the last. 2431N/A /** Return a list of all constructors defined by the given class. 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * Inaccessible members are not added to the last. 2431N/A /** Return a list of all fields defined by the given class. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * Inaccessible members are not added to the last. 2431N/A /** Return a list of all fields defined by the given class. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Returned fields will match the name (if not null) and the type (if not null). 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * Inaccessible members are not added to the last. 2431N/A /** Return a list of all nested types defined by the given class. 2431N/A * Super types are searched (for inherited members) if {@code searchSupers} is true. 2431N/A * Access checking is performed on behalf of the given {@code lookupClass}. 2431N/A * Inaccessible members are not added to the last. 1193N/A // fill the buffer with dummy structs for the JVM to fill in 1193N/A// System.out.println("Hello world! My methods are:"); 1193N/A// System.out.println(Factory.INSTANCE.getMethods(MemberName.class, true, null));