org.compass.core.util.reflection
Interface ReflectionMethod

All Known Implementing Classes:
PlainReflectionMethod

public interface ReflectionMethod

A wrapper around a Method allowing have different implemenatons of it.

Author:
kimchy

Method Summary
<A extends Annotation>
A
getAnnotation(Class<A> annotationType)
          Returns this element's annotation for the specified type if such an annotation is present, else null.
 Class<?> getDeclaringClass()
          Returns the Class object representing the class or interface that declares the member or constructor represented by this Member.
 Class[] getExceptionTypes()
          Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the underlying method represented by this IMethod object.
 Type getGenericReturnType()
          Returns a Type object that represents the formal return type of the method represented by this Method object.
 Method getMethod()
          Return a reference to the Method that this ReflectionMethod represent.
 int getModifiers()
          Returns the Java language modifiers for the member or constructor represented by this Member, as an integer.
 String getName()
          Returns the simple name of the underlying member or constructor represented by this Member.
 Class<?>[] getParameterTypes()
          Returns an array of Class objects that represent the formal parameter types, in declaration order, of the method represented by this Method object.
 Class<?> getReturnType()
          Returns a Class object that represents the formal return type of the method represented by this IMethod object.
 Object invoke(Object obj, Object... args)
          Invokes the underlying method represented by this IMethod object, on the specified object with the specified parameters.
 

Method Detail

getDeclaringClass

Class<?> getDeclaringClass()
Returns the Class object representing the class or interface that declares the member or constructor represented by this Member.

Returns:
an object representing the declaring class of the underlying member

getName

String getName()
Returns the simple name of the underlying member or constructor represented by this Member.

Returns:
the simple name of the underlying member

getModifiers

int getModifiers()
Returns the Java language modifiers for the member or constructor represented by this Member, as an integer. The Modifier class should be used to decode the modifiers in the integer.

Returns:
the Java language modifiers for the underlying member
See Also:
Modifier

getReturnType

Class<?> getReturnType()
Returns a Class object that represents the formal return type of the method represented by this IMethod object.

Returns:
the return type for the method this object represents

getParameterTypes

Class<?>[] getParameterTypes()
Returns an array of Class objects that represent the formal parameter types, in declaration order, of the method represented by this Method object. Returns an array of length 0 if the underlying method takes no parameters.

Returns:
the parameter types for the method this object represents

getExceptionTypes

Class[] getExceptionTypes()
Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the underlying method represented by this IMethod object. Returns an array of length 0 if the method declares no exceptions in its throws clause.

Returns:
the exception types declared as being thrown by the method this object represents

getAnnotation

<A extends Annotation> A getAnnotation(Class<A> annotationType)
Returns this element's annotation for the specified type if such an annotation is present, else null.

Parameters:
annotationType - the Class object corresponding to the annotation type
Returns:
this element's annotation for the specified annotation type if present on this element, else null
Throws:
NullPointerException - if annotationType is null
Since:
1.5

getGenericReturnType

Type getGenericReturnType()
Returns a Type object that represents the formal return type of the method represented by this Method object.

If the return type is a parameterized type, the Type object returned must accurately reflect the actual type parameters used in the source code.

If the return type is a type variable or a parameterized type, it is created. Otherwise, it is resolved.

Returns:
a Type object that represents the formal return type of the underlying method
Throws:
GenericSignatureFormatError - if the generic method signature does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
TypeNotPresentException - if the underlying method's return type refers to a non-existent type declaration
MalformedParameterizedTypeException - if the underlying method's return typed refers to a parameterized type that cannot be instantiated for any reason
Since:
1.5

invoke

Object invoke(Object obj,
              Object... args)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException
Invokes the underlying method represented by this IMethod object, on the specified object with the specified parameters. Individual parameters are automatically unwrapped to match primitive formal parameters, and both primitive and reference parameters are subject to method invocation conversions as necessary.

Parameters:
obj - the object the underlying method is invoked from
args - the arguments used for the method call
Returns:
the result of dispatching the method represented by this object on obj with parameters args
Throws:
IllegalAccessException - if this Method object enforces Java language access control and the underlying method is inaccessible.
IllegalArgumentException - if the method is an instance method and the specified object argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof); if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
InvocationTargetException - if the underlying method throws an exception.
NullPointerException - if the specified object is null and the method is an instance method.
ExceptionInInitializerError - if the initialization provoked by this method fails.

getMethod

Method getMethod()
Return a reference to the Method that this ReflectionMethod represent.



Copyright (c) 2004-2009 The Compass Project.