This file is a collection of reflection utilities for dealing with
methods and constructors.
| Method from org.apache.bsf.util.MethodUtils Detail: |
static int entryGetModifiers(Object entry) {
return (entry instanceof Method)
? ((Method)entry).getModifiers()
: ((Constructor)entry).getModifiers();
}
Utility function: obtain common data from either Method or
Constructor. (In lieu of an EntryPoint interface.) |
static String entryGetName(Object entry) {
return (entry instanceof Method)
? ((Method)entry).getName()
: ((Constructor)entry).getName();
}
Utility function: obtain common data from either Method or
Constructor. (In lieu of an EntryPoint interface.) |
static Class[] entryGetParameterTypes(Object entry) {
return (entry instanceof Method)
? ((Method)entry).getParameterTypes()
: ((Constructor)entry).getParameterTypes();
}
Utility function: obtain common data from either Method or
Constructor. (In lieu of an EntryPoint interface.) |
static String entryToString(Object entry) {
return (entry instanceof Method)
? ((Method)entry).toString()
: ((Constructor)entry).toString();
}
Utility function: obtain common data from either Method or
Constructor. (In lieu of an EntryPoint interface.) |
public static Constructor getConstructor(Class targetClass,
Class[] argTypes) throws SecurityException, NoSuchMethodException {
return (Constructor) getEntryPoint(targetClass,null,argTypes,true);
}
Class.getConstructor() finds only the entry point (if any)
_exactly_ matching the specified argument types. Our implmentation
can decide between several imperfect matches, using the same
search algorithm as the Java compiler.
Note that all constructors are static by definition, so
isStaticReference is true. |
public static Method getMethod(Object target,
String methodName,
Class[] argTypes) throws SecurityException, NoSuchMethodException {
boolean staticRef=target instanceof Class;
return getMethod( staticRef ? (Class)target : target.getClass(),
methodName,argTypes,staticRef);
}
Class.getMethod() finds only the entry point (if any) _exactly_
matching the specified argument types. Our implmentation can
decide between several imperfect matches, using the same search
algorithm as the Java compiler.
This version emulates the compiler behavior by allowing lookup to
be performed against either a class or an instance -- classname.foo()
must be a static method call, instance.foo() can invoke either static
or instance methods. |
public static Method getMethod(Class target,
String methodName,
Class[] argTypes,
boolean isStaticReference) throws SecurityException, NoSuchMethodException {
return (Method)getEntryPoint(target,methodName,argTypes,isStaticReference);
}
|