|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--bsh.Reflect
All of the reflection API code lies here. It is in the form of static utilities. See the design note about object wrappers in LHS.java for lamentations regarding this. Note: More work to do in here to fix up the extended signature matching. need to work in a search along with findMostSpecificSignature...
Note: there are lots of cases here where the Java reflection API makes us catch exceptions (e.g. NoSuchFieldException) in order to do basic searching. This has to be inefficient... I wish they would add a more normal Java API for locating fields.
Constructor Summary | |
(package private) |
Reflect()
|
Method Summary | |
private static java.lang.String |
accessorName(java.lang.String getorset,
java.lang.String propName)
|
(package private) static java.lang.Object |
constructObject(java.lang.Class clas,
java.lang.Object[] args)
Primary object constructor |
(package private) static java.lang.Object |
constructObject(java.lang.String clas,
java.lang.Object[] args)
|
private static java.lang.reflect.Field |
findAccessibleField(java.lang.Class clas,
java.lang.String fieldName)
Used when accessibility capability is available to locate an occurrance of the field in the most derived class or superclass and set its accessibility flag. |
(package private) static java.lang.reflect.Method |
findAccessibleMethod(java.lang.Class clas,
java.lang.String name,
java.lang.Class[] types,
boolean onlyStatic)
Locate a version of the method with the exact signature specified that is accessible via a public interface or through a public superclass or - if accessibility is on - through any interface or superclass. |
(package private) static java.lang.reflect.Constructor |
findExtendedConstructor(java.lang.Object[] args,
java.lang.reflect.Constructor[] constructors)
This uses the NameSpace.getAssignableForm() method to determine compatability of args. |
(package private) static java.lang.reflect.Method |
findExtendedMethod(java.lang.String name,
java.lang.Object[] args,
java.lang.reflect.Method[] methods)
This uses the NameSpace.getAssignableForm() method to determine compatability of args. |
(package private) static java.lang.reflect.Constructor |
findMostSpecificConstructor(java.lang.Class[] idealMatch,
java.lang.reflect.Constructor[] constructors)
|
(package private) static java.lang.reflect.Method |
findMostSpecificMethod(java.lang.String name,
java.lang.Class[] idealMatch,
java.lang.reflect.Method[] methods)
Implement JLS 15.11.2 for method resolution |
(package private) static int |
findMostSpecificSignature(java.lang.Class[] idealMatch,
java.lang.Class[][] candidates)
Implement JLS 15.11.2 Return the index of the most specific arguments match or -1 if no match is found. |
static java.lang.Class |
getArrayBaseType(java.lang.Class arrayClass)
Returns the base type of an array Class. |
static int |
getArrayDimensions(java.lang.Class arrayClass)
[ returns the dimensionality of the Class returns 0 if the Class is not an array class |
private static java.lang.reflect.Field |
getField(java.lang.Class clas,
java.lang.String fieldName)
All field lookup should come through here. |
private static java.lang.Object |
getFieldValue(java.lang.Class clas,
java.lang.Object object,
java.lang.String fieldName)
|
static java.lang.Object |
getIndex(java.lang.Object array,
int index)
|
(package private) static LHS |
getLHSObjectField(java.lang.Object object,
java.lang.String fieldName)
Get an LHS reference to an object field. |
(package private) static LHS |
getLHSStaticField(java.lang.Class clas,
java.lang.String fieldName)
|
static java.lang.Object |
getObjectField(java.lang.Object object,
java.lang.String fieldName)
|
static java.lang.Object |
getObjectProperty(java.lang.Object obj,
java.lang.String propName)
|
static java.lang.Object |
getStaticField(java.lang.Class clas,
java.lang.String fieldName)
|
static java.lang.Class[] |
getTypes(java.lang.Object[] args)
|
static boolean |
hasObjectPropertyGetter(java.lang.Class clas,
java.lang.String propName)
|
static boolean |
hasObjectPropertySetter(java.lang.Class clas,
java.lang.String propName)
|
private static java.lang.Object |
invokeMethod(java.lang.Class clas,
java.lang.Object object,
java.lang.String name,
java.lang.Object[] args,
boolean onlyStatic)
The full blown invoke method. |
static java.lang.Object |
invokeObjectMethod(Interpreter interpreter,
java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] args,
SimpleNode callerInfo)
Invoke method on object. |
static java.lang.Object |
invokeStaticMethod(java.lang.Class clas,
java.lang.String methodName,
java.lang.Object[] args)
Invoke a static method. |
(package private) static boolean |
isAssignable(java.lang.Class[] from,
java.lang.Class[] to)
Determine if the 'from' signature is assignable to the 'to' signature 'from' arg types, 'to' candidate types null value in 'to' type parameter indicates loose type. |
(package private) static boolean |
isAssignableFrom(java.lang.Class lhs,
java.lang.Class rhs)
This base method is meant to address a deficiency of Class.isAssignableFrom() which does not take primitive widening conversions into account. |
static java.lang.String |
normalizeClassName(java.lang.Class type)
This method is meant to convert a JVM-array class name to the correct 'fully-qualified name' for the array class - JLS 6.7 |
private static java.lang.reflect.Method[] |
retainStaticMethods(java.lang.reflect.Method[] methods)
Return only the static methods |
static void |
setIndex(java.lang.Object array,
int index,
java.lang.Object val)
|
static void |
setObjectProperty(java.lang.Object obj,
java.lang.String propName,
java.lang.Object value)
|
private static boolean |
showThisMethod(java.lang.String name)
Allow invocations of these method names on This type objects. |
private static java.lang.Object |
unwrapPrimitive(java.lang.Object arg)
|
private static void |
unwrapPrimitives(java.lang.Object[] args)
|
private static java.lang.Object |
wrapPrimitive(java.lang.Object value,
java.lang.Class returnType)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
Reflect()
Method Detail |
public static java.lang.Object invokeObjectMethod(Interpreter interpreter, java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, SimpleNode callerInfo) throws ReflectError, java.lang.reflect.InvocationTargetException, EvalError
callerInfo
- will be passed along in the caes where the method
is a bsh scripted method. It may be null to indicate no caller info.
ReflectError
java.lang.reflect.InvocationTargetException
EvalError
private static boolean showThisMethod(java.lang.String name)
public static java.lang.Object invokeStaticMethod(java.lang.Class clas, java.lang.String methodName, java.lang.Object[] args) throws ReflectError, java.lang.reflect.InvocationTargetException, EvalError
ReflectError
java.lang.reflect.InvocationTargetException
EvalError
public static java.lang.Object getIndex(java.lang.Object array, int index) throws ReflectError, TargetError
ReflectError
TargetError
public static void setIndex(java.lang.Object array, int index, java.lang.Object val) throws ReflectError, TargetError
ReflectError
TargetError
public static java.lang.Object getStaticField(java.lang.Class clas, java.lang.String fieldName) throws ReflectError
ReflectError
public static java.lang.Object getObjectField(java.lang.Object object, java.lang.String fieldName) throws ReflectError
ReflectError
static LHS getLHSStaticField(java.lang.Class clas, java.lang.String fieldName) throws ReflectError
ReflectError
static LHS getLHSObjectField(java.lang.Object object, java.lang.String fieldName) throws ReflectError
ReflectError
private static java.lang.Object getFieldValue(java.lang.Class clas, java.lang.Object object, java.lang.String fieldName) throws ReflectError
ReflectError
private static java.lang.reflect.Field getField(java.lang.Class clas, java.lang.String fieldName) throws ReflectError
ReflectError
private static java.lang.reflect.Field findAccessibleField(java.lang.Class clas, java.lang.String fieldName) throws java.lang.NoSuchFieldException
java.lang.NoSuchFieldException
private static java.lang.Object invokeMethod(java.lang.Class clas, java.lang.Object object, java.lang.String name, java.lang.Object[] args, boolean onlyStatic) throws ReflectError, java.lang.reflect.InvocationTargetException, EvalError
onlyStatic
- The method located must be static, the object param may be null.
Note: Method invocation could probably be speeded up if we eliminated
the throwing of exceptions in the search for the proper method.
We could probably cache our knowledge of method structure as well.
ReflectError
java.lang.reflect.InvocationTargetException
EvalError
private static java.lang.reflect.Method[] retainStaticMethods(java.lang.reflect.Method[] methods)
static java.lang.reflect.Method findAccessibleMethod(java.lang.Class clas, java.lang.String name, java.lang.Class[] types, boolean onlyStatic)
onlyStatic
- the method located must be static.
private static java.lang.Object wrapPrimitive(java.lang.Object value, java.lang.Class returnType) throws ReflectError
ReflectError
public static java.lang.Class[] getTypes(java.lang.Object[] args)
private static void unwrapPrimitives(java.lang.Object[] args)
private static java.lang.Object unwrapPrimitive(java.lang.Object arg)
static java.lang.Object constructObject(java.lang.String clas, java.lang.Object[] args) throws ReflectError, java.lang.reflect.InvocationTargetException
ReflectError
java.lang.reflect.InvocationTargetException
static java.lang.Object constructObject(java.lang.Class clas, java.lang.Object[] args) throws ReflectError, java.lang.reflect.InvocationTargetException
ReflectError
java.lang.reflect.InvocationTargetException
static java.lang.reflect.Method findMostSpecificMethod(java.lang.String name, java.lang.Class[] idealMatch, java.lang.reflect.Method[] methods)
static java.lang.reflect.Method findExtendedMethod(java.lang.String name, java.lang.Object[] args, java.lang.reflect.Method[] methods)
static java.lang.reflect.Constructor findMostSpecificConstructor(java.lang.Class[] idealMatch, java.lang.reflect.Constructor[] constructors)
static java.lang.reflect.Constructor findExtendedConstructor(java.lang.Object[] args, java.lang.reflect.Constructor[] constructors)
static int findMostSpecificSignature(java.lang.Class[] idealMatch, java.lang.Class[][] candidates)
static boolean isAssignable(java.lang.Class[] from, java.lang.Class[] to)
static boolean isAssignableFrom(java.lang.Class lhs, java.lang.Class rhs)
lhs
- assigning from rhs to lhsrhs
- assigning from rhs to lshprivate static java.lang.String accessorName(java.lang.String getorset, java.lang.String propName)
public static boolean hasObjectPropertyGetter(java.lang.Class clas, java.lang.String propName)
public static boolean hasObjectPropertySetter(java.lang.Class clas, java.lang.String propName)
public static java.lang.Object getObjectProperty(java.lang.Object obj, java.lang.String propName) throws ReflectError
ReflectError
public static void setObjectProperty(java.lang.Object obj, java.lang.String propName, java.lang.Object value) throws ReflectError, EvalError
ReflectError
EvalError
public static java.lang.String normalizeClassName(java.lang.Class type)
public static int getArrayDimensions(java.lang.Class arrayClass)
public static java.lang.Class getArrayBaseType(java.lang.Class arrayClass) throws ReflectError
ReflectError
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |