Methods Summary |
---|
public boolean | equals(java.lang.Object object)Indicates whether or not the specified {@code object} is equal to this
method. To be equal, the specified object must be an instance
of {@code Method} with the same declaring class and parameter types
as this method.
return object instanceof Method && toString().equals(object.toString());
|
public java.lang.annotation.Annotation[] | getDeclaredAnnotations()
return getDeclaredAnnotations(declaringClass, slot);
|
private native java.lang.annotation.Annotation[] | getDeclaredAnnotations(java.lang.Class declaringClass, int slot)
|
public java.lang.Class | getDeclaringClass()Returns the class that declares this method.
return declaringClass;
|
public java.lang.Object | getDefaultValue()Returns the default value for the annotation member represented by this
method.
return getDefaultValue(declaringClass, slot);
|
private native java.lang.Object | getDefaultValue(java.lang.Class declaringClass, int slot)
|
public java.lang.Class[] | getExceptionTypes()Returns the exception types as an array of {@code Class} instances. If
this method has no declared exceptions, an empty array is returned.
if (exceptionTypes == null) {
return new Class[0];
}
return exceptionTypes;
|
public java.lang.reflect.Type[] | getGenericExceptionTypes()Returns the exception types as an array of {@code Type} instances. If
this method has no declared exceptions, an empty array will be returned.
initGenericTypes();
return Types.getClonedTypeArray(genericExceptionTypes);
|
public java.lang.reflect.Type[] | getGenericParameterTypes()Returns the parameter types as an array of {@code Type} instances, in
declaration order. If this method has no parameters, an empty array is
returned.
initGenericTypes();
return Types.getClonedTypeArray(genericParameterTypes);
|
public java.lang.reflect.Type | getGenericReturnType()Returns the return type of this method as a {@code Type} instance.
initGenericTypes();
return Types.getType(genericReturnType);
|
private native int | getMethodModifiers(java.lang.Class decl_class, int slot)
|
public int | getModifiers()Returns the modifiers for this method. The {@link Modifier} class should
be used to decode the result.
return getMethodModifiers(declaringClass, slot);
|
public java.lang.String | getName()Returns the name of the method represented by this {@code Method}
instance.
return name;
|
public java.lang.annotation.Annotation[][] | getParameterAnnotations()Returns an array of arrays that represent the annotations of the formal
parameters of this method. If there are no parameters on this method,
then an empty array is returned. If there are no annotations set, then
and array of empty arrays is returned.
Annotation[][] parameterAnnotations
= getParameterAnnotations(declaringClass, slot);
if (parameterAnnotations.length == 0) {
return noAnnotations(parameterTypes.length);
}
return parameterAnnotations;
|
private native java.lang.annotation.Annotation[][] | getParameterAnnotations(java.lang.Class declaringClass, int slot)
|
public java.lang.Class[] | getParameterTypes()Returns an array of {@code Class} objects associated with the parameter
types of this method. If the method was declared with no parameters, an
empty array will be returned.
return parameterTypes;
|
public java.lang.Class | getReturnType()Returns the {@code Class} associated with the return type of this
method.
return returnType;
|
private java.lang.String | getSignature()Returns the constructor's signature in non-printable form. This is called
(only) from IO native code and needed for deriving the serialVersionUID
of the class
StringBuilder result = new StringBuilder();
result.append('(");
for(int i = 0; i < parameterTypes.length; i++) {
result.append(getSignature(parameterTypes[i]));
}
result.append(')");
result.append(getSignature(returnType));
return result.toString();
|
private native java.lang.Object[] | getSignatureAnnotation(java.lang.Class declaringClass, int slot)Returns the Signature annotation for this method. Returns {@code null} if
not found.
|
java.lang.String | getSignatureAttribute(){@inheritDoc}
Object[] annotation = getSignatureAnnotation(declaringClass, slot);
if (annotation == null) {
return null;
}
return StringUtils.combineStrings(annotation);
|
public java.lang.reflect.TypeVariable[] | getTypeParameters()
initGenericTypes();
return formalTypeParameters.clone();
|
public int | hashCode()Returns an integer hash code for this method. Objects which are equal
return the same value for this method. The hash code for this Method is
the hash code of the name of this method.
return name.hashCode();
|
private synchronized void | initGenericTypes()
if (!genericTypesAreInitialized) {
String signatureAttribute = getSignatureAttribute();
GenericSignatureParser parser = new GenericSignatureParser(
VMStack.getCallingClassLoader2());
parser.parseForMethod(this, signatureAttribute);
formalTypeParameters = parser.formalTypeParameters;
genericParameterTypes = parser.parameterTypes;
genericExceptionTypes = parser.exceptionTypes;
genericReturnType = parser.returnType;
genericTypesAreInitialized = true;
}
|
public java.lang.Object | invoke(java.lang.Object receiver, java.lang.Object args)Returns the result of dynamically invoking this method. This reproduces
the effect of {@code receiver.methodName(arg1, arg2, ... , argN)} This
method performs the following:
- If this method is static, the receiver argument is ignored.
- Otherwise, if the receiver is null, a NullPointerException is thrown.
- If the receiver is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
- If this Method object is enforcing access control (see
AccessibleObject) and this method is not accessible from the current
context, an IllegalAccessException is thrown.
- If the number of arguments passed and the number of parameters do not
match, an IllegalArgumentException is thrown.
- For each argument passed:
- If the corresponding parameter type is a primitive type, the argument
is unwrapped. If the unwrapping fails, an IllegalArgumentException is
thrown.
- If the resulting argument cannot be converted to the parameter type
via a widening conversion, an IllegalArgumentException is thrown.
- If this method is static, it is invoked directly. If it is
non-static, this method and the receiver are then used to perform a
standard dynamic method lookup. The resulting method is then invoked.
- If an exception is thrown during the invocation it is caught and
wrapped in an InvocationTargetException. This exception is then thrown.
- If the invocation completes normally, the return value itself is
returned. If the method is declared to return a primitive type, the
return value is first wrapped. If the return type is void, null is
returned.
if (args == null) {
args = new Object[0];
}
return invokeNative (receiver, args, declaringClass, parameterTypes, returnType, slot, flag);
|
private native java.lang.Object | invokeNative(java.lang.Object obj, java.lang.Object[] args, java.lang.Class declaringClass, java.lang.Class[] parameterTYpes, java.lang.Class returnType, int slot, boolean noAccessCheck)
|
public boolean | isBridge()Indicates whether or not this method is a bridge.
int modifiers = getMethodModifiers(declaringClass, slot);
return (modifiers & Modifier.BRIDGE) != 0;
|
public boolean | isSynthetic()Indicates whether or not this method is synthetic.
int modifiers = getMethodModifiers(declaringClass, slot);
return (modifiers & Modifier.SYNTHETIC) != 0;
|
public boolean | isVarArgs()Indicates whether or not this method takes a variable number argument.
int modifiers = getMethodModifiers(declaringClass, slot);
return (modifiers & Modifier.VARARGS) != 0;
|
static java.lang.annotation.Annotation[][] | noAnnotations(int size)Creates an array of empty Annotation arrays.
/*package*/
Annotation[][] annotations = new Annotation[size][];
for (int i = 0; i < size; i++) {
annotations[i] = NO_ANNOTATIONS;
}
return annotations;
|
public java.lang.String | toGenericString()Returns the string representation of the method's declaration, including
the type parameters.
StringBuilder sb = new StringBuilder(80);
initGenericTypes();
// append modifiers if any
int modifier = getModifiers();
if (modifier != 0) {
sb.append(Modifier.toString(modifier & ~(Modifier.BRIDGE +
Modifier.VARARGS))).append(' ");
}
// append type parameters
if (formalTypeParameters != null && formalTypeParameters.length > 0) {
sb.append('<");
for (int i = 0; i < formalTypeParameters.length; i++) {
appendGenericType(sb, formalTypeParameters[i]);
if (i < formalTypeParameters.length - 1) {
sb.append(", ");
}
}
sb.append("> ");
}
// append return type
appendGenericType(sb, Types.getType(genericReturnType));
sb.append(' ");
// append method name
appendArrayType(sb, getDeclaringClass());
sb.append("."+getName());
// append parameters
sb.append('(");
appendArrayGenericType(sb,
Types.getClonedTypeArray(genericParameterTypes));
sb.append(')");
// append exceptions if any
Type[] genericExceptionTypeArray = Types.getClonedTypeArray(
genericExceptionTypes);
if (genericExceptionTypeArray.length > 0) {
sb.append(" throws ");
appendArrayGenericType(sb, genericExceptionTypeArray);
}
return sb.toString();
|
public java.lang.String | toString()Returns a string containing a concise, human-readable description of this
method. The format of the string is:
- modifiers (if any)
- return type or 'void'
- declaring class name
- '('
- parameter types, separated by ',' (if any)
- ')'
- 'throws' plus exception types, separated by ',' (if any)
For example: {@code public native Object
java.lang.Method.invoke(Object,Object) throws
IllegalAccessException,IllegalArgumentException
,InvocationTargetException}
StringBuilder result = new StringBuilder(Modifier.toString(getModifiers()));
if (result.length() != 0)
result.append(' ");
result.append(returnType.getName());
result.append(' ");
result.append(declaringClass.getName());
result.append('.");
result.append(name);
result.append("(");
result.append(toString(parameterTypes));
result.append(")");
if (exceptionTypes != null && exceptionTypes.length != 0) {
result.append(" throws ");
result.append(toString(exceptionTypes));
}
return result.toString();
|