|
|||||||||
| Home >> All >> [ bsh overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
bsh
Class Reflect

java.lang.Objectbsh.Reflect
- class Reflect
- extends java.lang.Object
All of the reflection API code lies here. It is in the form of static utilities. Maybe this belongs in LHS.java or a generic object wrapper class. 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)
|
private static boolean |
argsAssignable(java.lang.Class[] parameters,
java.lang.Object[] args)
Arguments are assignable as defined by NameSpace.getAssignableForm() which takes into account special bsh conversions such as XThis and (ug) primitive wrapper promotion. |
(package private) static java.lang.Object |
constructObject(java.lang.Class clas,
java.lang.Object[] args)
Primary object constructor This method is simpler than those that must resolve general method invocation because constructors are not inherited. |
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)
findExtendedMethod uses the NameSpace.getAssignableForm() method to determine compatability of arguments. |
(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)
|
static java.lang.Object |
invokeCompiledCommand(java.lang.Class commandClass,
java.lang.Object[] args,
Interpreter interpreter,
CallStack callstack)
A command may be implemented as a compiled Java class containing one or more static invoke() methods of the correct signature. |
static java.lang.Object |
invokeObjectMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object[] args,
Interpreter interpreter,
CallStack callstack,
SimpleNode callerInfo)
Invoke method on arbitrary object. |
private static java.lang.Object |
invokeOnMethod(java.lang.reflect.Method method,
java.lang.Object object,
java.lang.Object[] args)
|
static java.lang.Object |
invokeStaticMethod(BshClassManager bcm,
java.lang.Class clas,
java.lang.String methodName,
java.lang.Object[] args)
Invoke a method known to be static. |
(package private) static boolean |
isJavaAssignableFrom(java.lang.Class lhs,
java.lang.Class rhs)
Is a standard Java assignment legal from the rhs type to the lhs type in a normal assignment? For Java primitive TYPE classes this method takes primitive promotion into account. |
private static boolean |
isSignatureAssignable(java.lang.Class[] from,
java.lang.Class[] to)
Is the 'from' signature (argument types) assignable to the 'to' signature (candidate method types) using isJavaAssignableFrom()? This method handles the special case of null values in 'to' types indicating a loose type and matching anything. |
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 boolean |
passThisMethod(java.lang.String name)
Allow invocations of these method names on This type objects. |
(package private) static java.lang.reflect.Method |
resolveJavaMethod(BshClassManager bcm,
java.lang.Class clas,
java.lang.Object object,
java.lang.String name,
java.lang.Object[] args,
boolean onlyStatic)
The full blown resolver method. |
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 java.lang.Object[] |
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
Reflect()
| Method Detail |
invokeObjectMethod
public static java.lang.Object invokeObjectMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object[] args, Interpreter interpreter, CallStack callstack, SimpleNode callerInfo) throws ReflectError, EvalError, java.lang.reflect.InvocationTargetException
- Invoke method on arbitrary object.
invocation may be static (through the object instance) or dynamic.
Object may be a bsh scripted object (This type).
invokeStaticMethod
public static java.lang.Object invokeStaticMethod(BshClassManager bcm, java.lang.Class clas, java.lang.String methodName, java.lang.Object[] args) throws ReflectError, UtilEvalError, java.lang.reflect.InvocationTargetException
- Invoke a method known to be static.
No object instance is needed and there is no possibility of the
method being a bsh scripted method.
invokeOnMethod
private static java.lang.Object invokeOnMethod(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object[] args) throws ReflectError, java.lang.reflect.InvocationTargetException
passThisMethod
private static boolean passThisMethod(java.lang.String name)
- Allow invocations of these method names on This type objects.
Don't give bsh.This a chance to override their behavior.
If the method is passed here the invocation will actually happen on the bsh.This object via the regular reflective method invocation mechanism. If not, then the method is evaluated by bsh.This itself as a scripted method call.
getIndex
public static java.lang.Object getIndex(java.lang.Object array, int index) throws ReflectError, UtilTargetError
setIndex
public static void setIndex(java.lang.Object array, int index, java.lang.Object val) throws ReflectError, UtilTargetError
getStaticField
public static java.lang.Object getStaticField(java.lang.Class clas, java.lang.String fieldName) throws UtilEvalError, ReflectError
getObjectField
public static java.lang.Object getObjectField(java.lang.Object object, java.lang.String fieldName) throws UtilEvalError, ReflectError
getLHSStaticField
static LHS getLHSStaticField(java.lang.Class clas, java.lang.String fieldName) throws UtilEvalError, ReflectError
getLHSObjectField
static LHS getLHSObjectField(java.lang.Object object, java.lang.String fieldName) throws UtilEvalError, ReflectError
- Get an LHS reference to an object field.
This method also deals with the field style property access.
In the field does not exist we check for a property setter.
getFieldValue
private static java.lang.Object getFieldValue(java.lang.Class clas, java.lang.Object object, java.lang.String fieldName) throws UtilEvalError, ReflectError
getField
private static java.lang.reflect.Field getField(java.lang.Class clas, java.lang.String fieldName) throws UtilEvalError, ReflectError
- All field lookup should come through here.
i.e. this method owns Class getField();
findAccessibleField
private static java.lang.reflect.Field findAccessibleField(java.lang.Class clas, java.lang.String fieldName) throws UtilEvalError, java.lang.NoSuchFieldException
- 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.
Note that this method is not needed in the simple non accessible
case because we don't have to hunt for fields.
Note that classes may declare overlapping private fields, so the
distinction about the most derived is important. Java doesn't normally
allow this kind of access (super won't show private variables) so
there is no real syntax for specifying which class scope to use...
resolveJavaMethod
static java.lang.reflect.Method resolveJavaMethod(BshClassManager bcm, java.lang.Class clas, java.lang.Object object, java.lang.String name, java.lang.Object[] args, boolean onlyStatic) throws ReflectError, UtilEvalError
- The full blown resolver method. Everybody should come here.
The method may be static or dynamic unless onlyStatic is set
(in which case object may be null).
retainStaticMethods
private static java.lang.reflect.Method[] retainStaticMethods(java.lang.reflect.Method[] methods)
- Return only the static methods
findAccessibleMethod
static java.lang.reflect.Method findAccessibleMethod(java.lang.Class clas, java.lang.String name, java.lang.Class[] types, boolean onlyStatic) throws UtilEvalError
- 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.
In the normal (non-accessible) case this still solves the problem that
arises when a package private class or private inner class implements a
public interface or derives from a public type.
wrapPrimitive
private static java.lang.Object wrapPrimitive(java.lang.Object value, java.lang.Class returnType) throws ReflectError
getTypes
public static java.lang.Class[] getTypes(java.lang.Object[] args)
unwrapPrimitives
private static java.lang.Object[] unwrapPrimitives(java.lang.Object[] args)
constructObject
static java.lang.Object constructObject(java.lang.Class clas, java.lang.Object[] args) throws ReflectError, java.lang.reflect.InvocationTargetException
- Primary object constructor
This method is simpler than those that must resolve general method
invocation because constructors are not inherited.
findMostSpecificMethod
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
findMostSpecificConstructor
static java.lang.reflect.Constructor findMostSpecificConstructor(java.lang.Class[] idealMatch, java.lang.reflect.Constructor[] constructors)
findExtendedMethod
static java.lang.reflect.Method findExtendedMethod(java.lang.String name, java.lang.Object[] args, java.lang.reflect.Method[] methods)
- findExtendedMethod uses the NameSpace.getAssignableForm() method to
determine compatability of arguments. This allows special (non
standard Java) bsh widening operations.
Note that this method examines the *arguments* themselves not the types.
findExtendedConstructor
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. This allows special (non standard Java) bsh
widening operations...
argsAssignable
private static boolean argsAssignable(java.lang.Class[] parameters, java.lang.Object[] args)
- Arguments are assignable as defined by NameSpace.getAssignableForm()
which takes into account special bsh conversions such as XThis and (ug)
primitive wrapper promotion.
findMostSpecificSignature
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.
isSignatureAssignable
private static boolean isSignatureAssignable(java.lang.Class[] from, java.lang.Class[] to)
- Is the 'from' signature (argument types) assignable to the 'to'
signature (candidate method types) using isJavaAssignableFrom()?
This method handles the special case of null values in 'to' types
indicating a loose type and matching anything.
isJavaAssignableFrom
static boolean isJavaAssignableFrom(java.lang.Class lhs, java.lang.Class rhs)
- Is a standard Java assignment legal from the rhs type to the lhs type
in a normal assignment?
For Java primitive TYPE classes this method takes primitive promotion
into account. The ordinary Class.isAssignableFrom() does not take
primitive promotion conversions into account. Note that Java allows
additional assignments without a cast in combination with variable
declarations. Those are handled elsewhere (maybe should be here with a
flag?)
This class accepts a null rhs type indicating that the rhs was the
value Primitive.NULL and allows it to be assigned to any object lhs
type (non primitive)
Note that the getAssignableForm() method in NameSpace is the primary
bsh method for checking assignability. It adds additional bsh
conversions, etc. (need to clarify what)
accessorName
private static java.lang.String accessorName(java.lang.String getorset, java.lang.String propName)
hasObjectPropertyGetter
public static boolean hasObjectPropertyGetter(java.lang.Class clas, java.lang.String propName)
hasObjectPropertySetter
public static boolean hasObjectPropertySetter(java.lang.Class clas, java.lang.String propName)
getObjectProperty
public static java.lang.Object getObjectProperty(java.lang.Object obj, java.lang.String propName) throws UtilEvalError, ReflectError
setObjectProperty
public static void setObjectProperty(java.lang.Object obj, java.lang.String propName, java.lang.Object value) throws ReflectError, UtilEvalError
normalizeClassName
public 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
getArrayDimensions
public static int getArrayDimensions(java.lang.Class arrayClass)
- returns the dimensionality of the Class
returns 0 if the Class is not an array class
getArrayBaseType
public static java.lang.Class getArrayBaseType(java.lang.Class arrayClass) throws ReflectError
- Returns the base type of an array Class.
throws ReflectError if the Class is not an array class.
invokeCompiledCommand
public static java.lang.Object invokeCompiledCommand(java.lang.Class commandClass, java.lang.Object[] args, Interpreter interpreter, CallStack callstack) throws UtilEvalError
- A command may be implemented as a compiled Java class containing one or
more static invoke() methods of the correct signature. The invoke()
methods must accept two additional leading arguments of the interpreter
and callstack, respectively. e.g. invoke(interpreter, callstack, ... )
This method adds the arguments and invokes the static method, returning
the result.
|
|||||||||
| Home >> All >> [ bsh overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
bsh.Reflect