Stub classes contain all of the fields of a BeanShell scripted class as well as two "callback" references to BeanShell namespaces: one for static methods and one for instance methods. Methods of the class are delegators which invoke corresponding methods on either the static or instance bsh object and then unpack and return the results. The static namespace utilizes a static import to delegate variable access to the class' static fields. The instance namespace utilizes a dynamic import (i.e. mixin) to delegate variable access to the class' instance variables.
Constructors for the class delegate to the static initInstance() method of ClassGeneratorUtil to initialize new instances of the object. initInstance() invokes the instance intializer code (init vars and instance blocks) and then delegates to the corresponding scripted constructor method in the instance namespace. Constructors contain special switch logic which allows the BeanShell to control the calling of alternate constructors (this() or super() references) at runtime.
Specially named superclass delegator methods are also generated in order to allow BeanShell to access overridden methods of the superclass (which reflection does not normally allow).
| Modifier and Type | Class and Description |
|---|---|
| public static class | ClassGeneratorUtil.ConstructorArgs
A ConstructorArgs object holds evaluated arguments for a constructor call as well as the index of a possible alternate selector to invoke. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final String | BSHCONSTRUCTORS
The bsh static namespace variable that holds the constructor methods |
| pack-priv static final String | BSHINIT
The bsh static namespace variable name of the instance initializer |
| pack-priv static final String | BSHSTATIC
The name of the static field holding the reference to the bsh static This (the callback namespace for static methods) |
| pack-priv static final String | BSHSUPER
The prefix for the name of the super delegate methods. |
| pack-priv static final String | BSHTHIS
The name of the instance field holding the reference to the bsh instance This (the callback namespace for instance methods) |
| pack-priv Modifiers | |
| pack-priv String | |
| pack-priv NameSpace | |
| pack-priv DelayedEvalBshMethod[] | |
| pack-priv static final int | DEFAULTCONSTRUCTOR
The switch branch number for the default constructor. |
| pack-priv String | fqClassName
fully qualified class name (with package) e.g. foo/bar/Blah |
| pack-priv Class | |
| pack-priv boolean | |
| pack-priv DelayedEvalBshMethod[] | |
| pack-priv static final String | |
| pack-priv Class | |
| pack-priv String | |
| pack-priv Constructor | |
| pack-priv Variable[] |
| Access | Constructor and Description |
|---|---|
| public | ClassGeneratorUtil(Modifiers classModifiers, String className, String
e.g. "com.foo.bar" packageName, Class<T> superClass, Class<T>[] interfaces, Variable[] vars, DelayedEvalBshMethod[] bshmethods, NameSpace classStaticNameSpace, boolean isInterface)
|
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | |
| private static String | |
| pack-priv static void | doSwitchBranch(int index, String targetClassName, String[] paramTypes, bsh.
|
| public byte[] | |
| pack-priv void | generateConstructor(int index, String[] paramTypes, int modifiers, bsh.
Generate a constructor. |
| pack-priv void | generateConstructorSwitch(int consIndex, int argsVar, int consArgsVar, bsh.
Generate a switch with a branch for each possible alternate constructor. |
| pack-priv static void | generateField(String fieldName, String type, int modifiers, bsh.
Generate a field - static or instance. |
| pack-priv static void | |
| public static void | generateParameterReifierCode(String[] paramTypes, boolean
the enclosing methods is static isStatic, final bsh.the code visitor to be used to generate the bytecode. cvGenerates the code to reify the arguments of the given method. |
| pack-priv static void | generatePlainReturnCode(String returnType, bsh.
Generate return code for a normal bytecode |
| public static void | generateReturnCode(String returnType, bsh.
the code visitor to be used to generate the bytecode. cvGenerates the code to unreify the result of the given method. |
| pack-priv static void | generateSuperDelegateMethod(String superClassName, String methodName, String returnType, String[] paramTypes, int modifiers, bsh.
Generate a superclass method delegate accessor method. |
| pack-priv static int | |
| private static String | |
| pack-priv static This | Returns: the class instance This object or null if the object has not been initialized.Get the instance bsh namespace field from the object instance. |
| pack-priv static This | getClassStaticThis(Class<T> clas, String
may be the name of clas itself or a superclass of clas. className)Get the static bsh namespace field from the class. |
| public static ClassGeneratorUtil. | Returns: the ConstructorArgs object containing a constructor selector and evaluated arguments for the alternate constructorthe arguments to the constructor. These are necessary in
the evaluation of the alt constructor args. e.g. Foo(a) { super(a); } consArgs, int index)Evaluate the arguments (if any) for the constructor specified by the constructor index. |
| pack-priv static String | |
| pack-priv static String[] | |
| public static void | |
| private static boolean | |
| public static void | startInterpreterForClass(Class<T> clas)
Attempt to load a script named for the class: e.g. Foo.class Foo.bsh. |
| BSHCONSTRUCTORS | back to summary |
|---|---|
| pack-priv static final String BSHCONSTRUCTORS The bsh static namespace variable that holds the constructor methods | |
| BSHINIT | back to summary |
|---|---|
| pack-priv static final String BSHINIT The bsh static namespace variable name of the instance initializer | |
| BSHSTATIC | back to summary |
|---|---|
| pack-priv static final String BSHSTATIC The name of the static field holding the reference to the bsh static This (the callback namespace for static methods) | |
| BSHSUPER | back to summary |
|---|---|
| pack-priv static final String BSHSUPER The prefix for the name of the super delegate methods. e.g. _bshSuperfoo() is equivalent to super.foo() | |
| BSHTHIS | back to summary |
|---|---|
| pack-priv static final String BSHTHIS The name of the instance field holding the reference to the bsh instance This (the callback namespace for instance methods) | |
| classModifiers | back to summary |
|---|---|
| pack-priv Modifiers classModifiers | |
| className | back to summary |
|---|---|
| pack-priv String className | |
| classStaticNameSpace | back to summary |
|---|---|
| pack-priv NameSpace classStaticNameSpace | |
| constructors | back to summary |
|---|---|
| pack-priv DelayedEvalBshMethod[] constructors | |
| DEFAULTCONSTRUCTOR | back to summary |
|---|---|
| pack-priv static final int DEFAULTCONSTRUCTOR The switch branch number for the default constructor. The value -1 will cause the default branch to be taken. | |
| fqClassName | back to summary |
|---|---|
| pack-priv String fqClassName fully qualified class name (with package) e.g. foo/bar/Blah | |
| interfaces | back to summary |
|---|---|
| pack-priv Class<T>[] interfaces | |
| isInterface | back to summary |
|---|---|
| pack-priv boolean isInterface | |
| methods | back to summary |
|---|---|
| pack-priv DelayedEvalBshMethod[] methods | |
| OBJECT | back to summary |
|---|---|
| pack-priv static final String OBJECT | |
| superClass | back to summary |
|---|---|
| pack-priv Class<T> superClass | |
| superClassName | back to summary |
|---|---|
| pack-priv String superClassName | |
| superConstructors | back to summary |
|---|---|
| pack-priv Constructor<T>[] superConstructors | |
| vars | back to summary |
|---|---|
| pack-priv Variable[] vars | |
| ClassGeneratorUtil | back to summary |
|---|---|
public ClassGeneratorUtil(Modifiers classModifiers, String className, String packageName, Class<T> superClass, Class<T>[] interfaces, Variable[] vars, DelayedEvalBshMethod[] bshmethods, NameSpace classStaticNameSpace, boolean isInterface)
| |
| classContainsMethod | back to summary |
|---|---|
| pack-priv boolean classContainsMethod(Class<T> clas, String methodName, String[] paramTypes) | |
| descriptorToClassName | back to summary |
|---|---|
| private static String descriptorToClassName(String s) If a non-array object type, remove the prefix "L" and suffix ";". | |
| doSwitchBranch | back to summary |
|---|---|
| pack-priv static void doSwitchBranch(int index, String targetClassName, String[] paramTypes, bsh. | |
| generateClass | back to summary |
|---|---|
| public byte[] generateClass() Generate the class bytecode for this class. | |
| generateConstructor | back to summary |
|---|---|
| pack-priv void generateConstructor(int index, String[] paramTypes, int modifiers, bsh. Generate a constructor. | |
| generateConstructorSwitch | back to summary |
|---|---|
| pack-priv void generateConstructorSwitch(int consIndex, int argsVar, int consArgsVar, bsh. Generate a switch with a branch for each possible alternate constructor. This includes all superclass constructors and all constructors of this class. The default branch of this switch is the default superclass constructor. This method also generates the code to call the static ClassGeneratorUtil getConstructorArgs() method which inspects the scripted constructor to find the alternate constructor signature (if any) and evalute the arguments at runtime. The getConstructorArgs() method returns the actual arguments as well as the index of the constructor to call. | |
| generateField | back to summary |
|---|---|
| pack-priv static void generateField(String fieldName, String type, int modifiers, bsh. Generate a field - static or instance. | |
| generateMethod | back to summary |
|---|---|
| pack-priv static void generateMethod(String className, String fqClassName, String methodName, String returnType, String[] paramTypes, int modifiers, bsh. Generate a delegate method - static or instance. The generated code packs the method arguments into an object array (wrapping primitive types in bsh.Primitive), invokes the static or instance namespace invokeMethod() method, and then unwraps / returns the result. | |
| generateParameterReifierCode | back to summary |
|---|---|
| public static void generateParameterReifierCode(String[] paramTypes, boolean isStatic, final bsh. Generates the code to reify the arguments of the given method. For a method "int m (int i, String s)", this code is the bytecode corresponding to the "new Object[] { new bsh.Primitive(i), s }" expression.
| |
| generatePlainReturnCode | back to summary |
|---|---|
| pack-priv static void generatePlainReturnCode(String returnType, bsh. Generate return code for a normal bytecode | |
| generateReturnCode | back to summary |
|---|---|
| public static void generateReturnCode(String returnType, bsh. Generates the code to unreify the result of the given method. For a method "int m (int i, String s)", this code is the bytecode corresponding to the "((Integer)...).intValue()" expression.
| |
| generateSuperDelegateMethod | back to summary |
|---|---|
| pack-priv static void generateSuperDelegateMethod(String superClassName, String methodName, String returnType, String[] paramTypes, int modifiers, bsh. Generate a superclass method delegate accessor method. These methods are specially named methods which allow access to overridden methods of the superclass (which the Java reflection API normally does not allow). | |
| getASMModifiers | back to summary |
|---|---|
| pack-priv static int getASMModifiers(Modifiers modifiers) Translate bsh.Modifiers into ASM modifier bitflags. | |
| getBaseName | back to summary |
|---|---|
| private static String getBaseName(String className) | |
| getClassInstanceThis | back to summary |
|---|---|
| pack-priv static This getClassInstanceThis(Object instance, String className) Get the instance bsh namespace field from the object instance.
| |
| getClassStaticThis | back to summary |
|---|---|
| pack-priv static This getClassStaticThis(Class<T> clas, String className) Get the static bsh namespace field from the class.
| |
| getConstructorArgs | back to summary |
|---|---|
| public static ClassGeneratorUtil. Evaluate the arguments (if any) for the constructor specified by the constructor index. Return the ConstructorArgs object which contains the actual arguments to the alternate constructor and also the index of that constructor for the constructor switch.
| |
| getMethodDescriptor | back to summary |
|---|---|
| pack-priv static String getMethodDescriptor(String returnType, String[] paramTypes) | |
| getTypeDescriptors | back to summary |
|---|---|
| pack-priv static String[] getTypeDescriptors(Class<T>[] cparams) | |
| initInstance | back to summary |
|---|---|
| public static void initInstance(Object instance, String className, Object[] args) Initialize an instance of the class. This method is called from the **generated class** constructor to evaluate the instance initializer and scripted constructor in the instance namespace. | |
| isPrimitive | back to summary |
|---|---|
| private static boolean isPrimitive(String typeDescriptor) Does the type descriptor string describe a primitive type? | |
| startInterpreterForClass | back to summary |
|---|---|
| public static void startInterpreterForClass(Class<T> clas) Attempt to load a script named for the class: e.g. Foo.class Foo.bsh. The script is expected to (at minimum) initialize the class body. That is, it should contain the scripted class definition. This method relies on the fact that the ClassGenerator generateClass() method will detect that the generated class already exists and initialize it rather than recreating it. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| pack-priv Object[] | |
| public static ClassGeneratorUtil. | DEFAULT
A ConstructorArgs which calls the default constructor |
| public int |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public byte | |
| public char | |
| public double | |
| public float | |
| public int | |
| public long | |
| public Object | |
| public short | |
| pack-priv Object |
| arg | back to summary |
|---|---|
| pack-priv int arg | |
| args | back to summary |
|---|---|
| pack-priv Object[] args | |
| DEFAULT | back to summary |
|---|---|
| public static ClassGeneratorUtil. A ConstructorArgs which calls the default constructor | |
| selector | back to summary |
|---|---|
| public int selector | |
| ConstructorArgs | back to summary |
|---|---|
| pack-priv ConstructorArgs() The index of the constructor to call. | |
| ConstructorArgs | back to summary |
|---|---|
| pack-priv ConstructorArgs(int selector, Object[] args) | |
| getBoolean | back to summary |
|---|---|
| public boolean getBoolean() | |
| getByte | back to summary |
|---|---|
| public byte getByte() | |
| getChar | back to summary |
|---|---|
| public char getChar() | |
| getDouble | back to summary |
|---|---|
| public double getDouble() | |
| getFloat | back to summary |
|---|---|
| public float getFloat() | |
| getInt | back to summary |
|---|---|
| public int getInt() | |
| getLong | back to summary |
|---|---|
| public long getLong() | |
| getObject | back to summary |
|---|---|
| public Object getObject() | |
| getShort | back to summary |
|---|---|
| public short getShort() | |
| next | back to summary |
|---|---|
| pack-priv Object next() | |