bsh
Class Types

java.lang.Object
  extended bybsh.Types

class Types
extends java.lang.Object

Static routines supporing type comparison and conversion in BeanShell.


Field Summary
(package private) static int ASSIGNMENT
           
(package private) static int CAST
           
(package private) static Primitive INVALID_CAST
           
(package private) static Primitive VALID_CAST
          Special value that indicates by identity that the result of a cast operation was a valid cast.
 
Constructor Summary
(package private) Types()
           
 
Method Summary
(package private) static boolean argsAssignable(java.lang.Class[] parameters, java.lang.Object[] args)
          Deprecated. fix this! need to stop catching exception
(package private) static UtilEvalError castError(java.lang.Class lhsType, java.lang.Class rhsType, int operation)
          Return a UtilEvalError or UtilTargetError wrapping a ClassCastException describing an illegal assignment or illegal cast, respectively.
(package private) static UtilEvalError castError(java.lang.String lhs, java.lang.String rhs, int operation)
           
(package private) static java.lang.Object castObject(java.lang.Class toType, java.lang.Class fromType, java.lang.Object fromValue, int operation, boolean checkOnly)
           
static java.lang.Object castObject(java.lang.Object fromValue, java.lang.Class toType, int operation)
          Attempt to cast an object instance to a new type.
static java.lang.Object getAssignableForm(java.lang.Object rhs, java.lang.Class lhsType)
          Deprecated. Getting rid of this... Use isBshAssignable(...) and castObject(...)
static java.lang.Class[] getTypes(java.lang.Object[] args)
          Get the Java types of the arguments.
(package private) static boolean isBshAssignable(java.lang.Class toType, java.lang.Class fromType)
           
(package private) static boolean isJavaAssignable(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 (i.e.
(package 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 isJavaAssignable()? This method handles the special case of null values in 'to' types indicating a loose type and matching anything.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAST

static final int CAST
See Also:
Constant Field Values

ASSIGNMENT

static final int ASSIGNMENT
See Also:
Constant Field Values

VALID_CAST

static Primitive VALID_CAST
Special value that indicates by identity that the result of a cast operation was a valid cast. This is used by castObject() and castPrimitive() in the checkOnly mode of operation. This value is a Primitive type so that it can be returned by castPrimitive.


INVALID_CAST

static Primitive INVALID_CAST
Constructor Detail

Types

Types()
Method Detail

getTypes

public static java.lang.Class[] getTypes(java.lang.Object[] args)
Get the Java types of the arguments.


argsAssignable

static boolean argsAssignable(java.lang.Class[] parameters,
                              java.lang.Object[] args)
Deprecated. fix this! need to stop catching exception

Arguments are assignable as defined by Types.getAssignableForm() which takes into account special bsh conversions such as XThis and primitive wrapper promotion.


isSignatureAssignable

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 isJavaAssignable()? This method handles the special case of null values in 'to' types indicating a loose type and matching anything.


isJavaAssignable

static boolean isJavaAssignable(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 (i.e. without any cast)?

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 is the primary bsh method for checking assignability. It adds additional bsh conversions, etc.

Parameters:
lhs - assigning from rhs to lhs
rhs - assigning from rhs to lhs
See Also:
isBshAssignable( Class, Class )

getAssignableForm

public static java.lang.Object getAssignableForm(java.lang.Object rhs,
                                                 java.lang.Class lhsType)
                                          throws UtilEvalError
Deprecated. Getting rid of this... Use isBshAssignable(...) and castObject(...)

Parameters:
rhs - may be Primitive
lhsType - is java type or TYPE
Throws:
UtilEvalError

castObject

public static java.lang.Object castObject(java.lang.Object fromValue,
                                          java.lang.Class toType,
                                          int operation)
                                   throws UtilEvalError
Attempt to cast an object instance to a new type. This method can handle fromValue Primitive types (representing primitive casts) as well as fromValue object casts requiring interface generation, etc.

Parameters:
toType - the class type of the cast result, which may include primitive types, e.g. Byte.TYPE
fromValue - an Object or bsh.Primitive primitive value (including Primitive.NULL or Primitive.VOID )
Throws:
UtilEvalError
See Also:
isBshAssignable( Class, Class )

isBshAssignable

static boolean isBshAssignable(java.lang.Class toType,
                               java.lang.Class fromType)

castObject

static java.lang.Object castObject(java.lang.Class toType,
                                   java.lang.Class fromType,
                                   java.lang.Object fromValue,
                                   int operation,
                                   boolean checkOnly)
                            throws UtilEvalError
Throws:
UtilEvalError

castError

static UtilEvalError castError(java.lang.Class lhsType,
                               java.lang.Class rhsType,
                               int operation)
Return a UtilEvalError or UtilTargetError wrapping a ClassCastException describing an illegal assignment or illegal cast, respectively.


castError

static UtilEvalError castError(java.lang.String lhs,
                               java.lang.String rhs,
                               int operation)