kmy.jint.util
Class AnyUtilities

java.lang.Object
  |
  +--kmy.jint.util.AnyUtilities

public class AnyUtilities
extends java.lang.Object
implements TokenConst

AnyUtilities is a class with many static methods that are used to support kmy.jint.lang.Any pseudo-class at runtime.

Values that are explicitly or implicitly declared as Any are really just Objects, but all operations on them are deferred till runtime. For example, accessing a field of such object requires dynamic lookup through java reflection.

There is also a special case of Any - an object that implements kmy.jint.util.Dispatch interface. These objects are given opportunity to handle field access and method invocation themselves.


Inner Class Summary
(package private) static class AnyUtilities.CacheEntry
           
(package private) static class AnyUtilities.FCacheEntry
           
 
Field Summary
private static AnyUtilities.CacheEntry[] cache
           
private static int CACHE_BITS
           
private static int CACHE_MASK
           
private static int CACHE_SIZE
           
static boolean cacheOff
           
private static ClassUtilities cutilities
           
private static java.lang.reflect.Method[] EMPTY
           
private static java.lang.Class[] EMPTYT
           
private static AnyUtilities.FCacheEntry[] fcache
           
private static java.lang.Object lock
           
static int MATCH_FAIL
           
static int MATCH_OK
           
static int MATCH_PERFECT
           
private static java.lang.Object NULL
           
private static java.lang.Class[] OBJCLASS
           
private static ClassUtilities utilities
           
 
Fields inherited from interface kmy.jint.constants.TokenConst
TOK_OPT_BUFFERONLY, TOK_OPT_DECLARE, TOK_OPT_GLOBAL, TOK_OPT_IGNORE, TOK_OPT_MULTILINE, TOK_OPT_OFFLINE, TOK_OPT_RETAINALL, TOK_OPT_SINGLELINE, TOK_OPT_STANDALONE, TOKEN_ABSTRACT, TOKEN_AE, TOKEN_AND, TOKEN_ANDE, TOKEN_BOOLEAN, TOKEN_BREAK, TOKEN_BYTE, TOKEN_BYVALUE, TOKEN_CASE, TOKEN_CATCH, TOKEN_CHAR, TOKEN_CLASS, TOKEN_CONST, TOKEN_CONTINUE, TOKEN_DEFAULT, TOKEN_DO, TOKEN_DOUBLE, TOKEN_EE, TOKEN_ELSE, TOKEN_EOF, TOKEN_EXTENDS, TOKEN_FALSE, TOKEN_FINAL, TOKEN_FINALLY, TOKEN_FLOAT, TOKEN_FOR, TOKEN_GE, TOKEN_GG, TOKEN_GGE, TOKEN_GGG, TOKEN_GGGE, TOKEN_GOTO, TOKEN_IF, TOKEN_IMPLEMENTS, TOKEN_IMPORT, TOKEN_INSTANCEOF, TOKEN_INT, TOKEN_INTERFACE, TOKEN_LE, TOKEN_LL, TOKEN_LLE, TOKEN_LONG, TOKEN_ME, TOKEN_MM, TOKEN_NATIVE, TOKEN_NE, TOKEN_NEW, TOKEN_NONE, TOKEN_NULL, TOKEN_OR, TOKEN_ORE, TOKEN_PACKAGE, TOKEN_PCE, TOKEN_PE, TOKEN_PP, TOKEN_PRIVATE, TOKEN_PROTECTED, TOKEN_PUBLIC, TOKEN_RETURN, TOKEN_SE, TOKEN_SHORT, TOKEN_SS, TOKEN_STATIC, TOKEN_SUPER, TOKEN_SWITCH, TOKEN_SYNCHRONIZED, TOKEN_TE, TOKEN_THIS, TOKEN_THREADSAFE, TOKEN_THROW, TOKEN_THROWS, TOKEN_TRANSIENT, TOKEN_TRUE, TOKEN_TRY, TOKEN_V_BOUND, TOKEN_V_CHAR, TOKEN_V_DOUBLE, TOKEN_V_FLOAT, TOKEN_V_FORM, TOKEN_V_INT, TOKEN_V_LONG, TOKEN_V_PATT, TOKEN_V_REGEX, TOKEN_V_STRING, TOKEN_V_SUBST, TOKEN_V_TRANS, TOKEN_VOID, TOKEN_VOLATILE, TOKEN_WHERE, TOKEN_WHILE, TOKEN_WORD, TOKEN_XE, UNARY_MINUS
 
Constructor Summary
AnyUtilities()
           
 
Method Summary
(package private) static void ()
           
static java.lang.Object callMethod(java.lang.Object target, java.lang.Class targetClass, java.lang.String name, java.lang.Class[] types, java.lang.Object[] args, int cacheId)
          Calls targetClass's method that is named name and has signature that matches parameter types given in argument type using instance specified by target.
static java.lang.Object callMethod(java.lang.Object target, java.lang.String name, java.lang.Class[] types, java.lang.Object[] args, int cacheId)
          Same as the other callMethod method, with targetClass = target.getClass().
static java.lang.Object callMethod0(java.lang.Object target, java.lang.Class targetClass, java.lang.String name, java.lang.Class[] types, java.lang.Object[] args, int cacheId)
          Calls target's method that is named name and has signature that matches parameter types given in argument type.
static java.lang.Class commonClass(java.lang.Class c1, java.lang.Class c2)
          Given two classes that represent numbers, returns the class that should be used to store the result of operation (like '+' or '*") applied to the objects of these classes.
static boolean cond(int op, java.lang.Object arg1, java.lang.Object arg2)
          Evaluates condition (like '<' or '>') on a pair of objects.
static java.lang.Object[] convertArgs(java.lang.Object[] args, java.lang.Class[] types)
          Converts actaul parameter values in array args to types specified in array types.
static java.lang.Object convertNumber(java.lang.Object in, java.lang.Class clazz)
          Converts a number object in into an object specified by class clazz.
static java.lang.reflect.Field findField(java.lang.Object target, java.lang.String name, int cacheId)
          Find a field in the class of target by its name.
static java.lang.Object getElement(java.lang.Object table, java.lang.Object key)
          Returns an element of a vector or dictionary table by its index or key key.
static java.lang.Object getField(java.lang.Object target, java.lang.String name, int cacheID)
          Returns value of the field name in object target.
static java.lang.Object getField0(java.lang.Object target, java.lang.String name, int cacheID)
          Returns value of the field name in object target.
static int intValue(java.lang.Object v)
          Returns integer value of Character or Number object.
static boolean isWrapped(java.lang.Object obj)
          Returns true if obj is a wrapper object, such as Boolean or Character.
static int match(java.lang.Class value, java.lang.Class var)
          Matches actual parameter or value type (value) with formal parameter or variable type (var).
static java.lang.Object newAny()
          This method is called to implement Jint 'new Any()' expression.
static java.lang.Object op(int op, java.lang.Object arg1)
          Performs a prefix operation on an object.
static java.lang.Object op(int op, java.lang.Object arg1, java.lang.Object arg2)
          Performs an infix operation on a pair of objects.
static void putElement(java.lang.Object table, java.lang.Object key, java.lang.Object value)
          Sets element of a vector or dictionary table by its index or key key to value.
static void setField(java.lang.Object target, java.lang.Object value, java.lang.String name, int cacheID)
          Sets value of the field name in object target to value.
static void setField0(java.lang.Object target, java.lang.Object value, java.lang.String name, int cacheID)
          Sets value of the field name in object target.
static java.lang.Object shift(int op, java.lang.Object arg, int sh)
          Performs shift ( '<<', '>>', or '>>>' ) on an object.
static java.lang.Object textSearch(java.lang.Object text, java.lang.Object textProc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EMPTY

private static final java.lang.reflect.Method[] EMPTY

OBJCLASS

private static final java.lang.Class[] OBJCLASS

NULL

private static final java.lang.Object NULL

EMPTYT

private static final java.lang.Class[] EMPTYT

MATCH_OK

public static final int MATCH_OK

MATCH_PERFECT

public static final int MATCH_PERFECT

MATCH_FAIL

public static final int MATCH_FAIL

cacheOff

public static final boolean cacheOff

utilities

private static ClassUtilities utilities

cutilities

private static ClassUtilities cutilities

lock

private static java.lang.Object lock

CACHE_BITS

private static int CACHE_BITS

CACHE_SIZE

private static int CACHE_SIZE

CACHE_MASK

private static int CACHE_MASK

cache

private static AnyUtilities.CacheEntry[] cache

fcache

private static AnyUtilities.FCacheEntry[] fcache
Constructor Detail

AnyUtilities

public AnyUtilities()
Method Detail

static void ()

convertNumber

public static java.lang.Object convertNumber(java.lang.Object in,
                                             java.lang.Class clazz)
Converts a number object in into an object specified by class clazz. Character is considered to be a number too.

isWrapped

public static boolean isWrapped(java.lang.Object obj)
Returns true if obj is a wrapper object, such as Boolean or Character.

commonClass

public static java.lang.Class commonClass(java.lang.Class c1,
                                          java.lang.Class c2)
Given two classes that represent numbers, returns the class that should be used to store the result of operation (like '+' or '*") applied to the objects of these classes.

match

public static int match(java.lang.Class value,
                        java.lang.Class var)
Matches actual parameter or value type (value) with formal parameter or variable type (var). Returns MATCH_PERFECT if they are the same (type and its wrapper class are considered to be a perfect match), MATCH_OK, if they differ but assignement still can be made, and MATCH_FAIL if assignment cannot be made.

findField

public static java.lang.reflect.Field findField(java.lang.Object target,
                                                java.lang.String name,
                                                int cacheId)
                                         throws DispatchException
Find a field in the class of target by its name. cacheId allows this class to cache found field information, so subsequent call with the same parameters can be faster.

getField0

public static java.lang.Object getField0(java.lang.Object target,
                                         java.lang.String name,
                                         int cacheID)
                                  throws DispatchException
Returns value of the field name in object target. Integer parameter cacheID is used for caching.

getField

public static java.lang.Object getField(java.lang.Object target,
                                        java.lang.String name,
                                        int cacheID)
Returns value of the field name in object target. If target is an instance of Dispatch interface, its getField method is called instead. If target is an array and name == "length", an Integer object that contains length of the array is returned. Integer parameter cacheID is used for caching.

setField0

public static void setField0(java.lang.Object target,
                             java.lang.Object value,
                             java.lang.String name,
                             int cacheID)
                      throws DispatchException
Sets value of the field name in object target. Integer parameter cacheID is used for caching.

setField

public static void setField(java.lang.Object target,
                            java.lang.Object value,
                            java.lang.String name,
                            int cacheID)
Sets value of the field name in object target to value. If target is an instance of Dispatch interface, its setField method is called instead. Integer parameter cacheID is used for caching.

callMethod0

public static java.lang.Object callMethod0(java.lang.Object target,
                                           java.lang.Class targetClass,
                                           java.lang.String name,
                                           java.lang.Class[] types,
                                           java.lang.Object[] args,
                                           int cacheId)
                                    throws java.lang.Exception
Calls target's method that is named name and has signature that matches parameter types given in argument type. Argument args specifies actual parameter values. Argument cacheID is used for caching, so the next time method can be found faster. Jint variable-length parameter list (ArgList) is supported. Actual call is done through Java reflection.

callMethod

public static java.lang.Object callMethod(java.lang.Object target,
                                          java.lang.Class targetClass,
                                          java.lang.String name,
                                          java.lang.Class[] types,
                                          java.lang.Object[] args,
                                          int cacheId)
                                   throws java.lang.Exception
Calls targetClass's method that is named name and has signature that matches parameter types given in argument type using instance specified by target. Target can be null for constructors and static methods. Constructors can be accessed by specifying "" as a method name. Argument args specifies actual parameter values. Argument cacheID is used for caching, so the next time method can be found faster. Any element in array type that has value null is filled by the corresponding actual parameter value's class. Jint variable-length parameter list (ArgList) is supported. Actual call is done through Java reflection if target is not an instance of kmy.jint.util.Dispatch; if it is, Dispatch.callMethod method is called.

callMethod

public static java.lang.Object callMethod(java.lang.Object target,
                                          java.lang.String name,
                                          java.lang.Class[] types,
                                          java.lang.Object[] args,
                                          int cacheId)
                                   throws java.lang.Exception
Same as the other callMethod method, with targetClass = target.getClass().

convertArgs

public static java.lang.Object[] convertArgs(java.lang.Object[] args,
                                             java.lang.Class[] types)
Converts actaul parameter values in array args to types specified in array types. It involves converting objects representing numbers to corrrect type and collapsing argument list, if the last parameter type is ArgList and either actual parameter list length differs from parameter type list length or last actual parameter is not an instance of ArgList. Returns array of converted parameter values.

op

public static java.lang.Object op(int op,
                                  java.lang.Object arg1)
Performs a prefix operation on an object. Prefix operations are: '+', '-', '~', '!'.

op

public static java.lang.Object op(int op,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2)
Performs an infix operation on a pair of objects.

cond

public static boolean cond(int op,
                           java.lang.Object arg1,
                           java.lang.Object arg2)
Evaluates condition (like '<' or '>') on a pair of objects.

shift

public static java.lang.Object shift(int op,
                                     java.lang.Object arg,
                                     int sh)
Performs shift ( '<<', '>>', or '>>>' ) on an object.

intValue

public static int intValue(java.lang.Object v)
Returns integer value of Character or Number object.

getElement

public static java.lang.Object getElement(java.lang.Object table,
                                          java.lang.Object key)
Returns an element of a vector or dictionary table by its index or key key. If table is an instance of kmy.jint.util.Dispatch, then its getElement is called.

putElement

public static void putElement(java.lang.Object table,
                              java.lang.Object key,
                              java.lang.Object value)
Sets element of a vector or dictionary table by its index or key key to value. If table is an instance of kmy.jint.util.Dispatch, then its setElement is called.

newAny

public static java.lang.Object newAny()
This method is called to implement Jint 'new Any()' expression. It creates an instance of DispatchObject.

textSearch

public static java.lang.Object textSearch(java.lang.Object text,
                                          java.lang.Object textProc)