|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.quilt.cl.ClassFactory
Class synthesizer. Currently intended for debugging Quilt
development and limited to instantiating classes with a
no-argument constructor and a single method whose bytecode
depends upon the base name of the class.
By default classes whose name begins with test.data.Test
will be synthesized. This can be set to a different string by a
QuiltClassLoader method.
QuiltClassLoader.
Method Summary | |
static ClassFactory |
getInstance()
Use this method to get to the ClassFactory singleton. |
java.io.InputStream |
getResourceAsStream(java.lang.String resName)
Get the bytecode for a synthesized class. |
org.apache.bcel.generic.ClassGen |
makeClass(java.lang.String className,
java.lang.String fileName)
Generate a class with a single no-arg constructor and a runTest method. |
org.apache.bcel.generic.MethodGen |
makeConstructor(org.apache.bcel.generic.ClassGen clazz)
Creates the constructor for the synthesized class. |
org.apache.bcel.generic.MethodGen |
makeMethod(org.apache.bcel.generic.ClassGen clazz)
Creates a method with bytecode determined by the name of the class. |
org.apache.bcel.generic.MethodGen |
mgDefault(org.apache.bcel.generic.ClassGen clazz)
Generates bytecode for a method which simply returns 2. |
org.apache.bcel.generic.MethodGen |
mgIfThen(org.apache.bcel.generic.ClassGen clazz)
Generates instructions for a method consisting of a single if-then clause. |
org.apache.bcel.generic.MethodGen |
mgNPENoCatch(org.apache.bcel.generic.ClassGen clazz)
Creates bytecode which will throw a NullPointerException without a catch block. |
org.apache.bcel.generic.MethodGen |
mgNPEWithCatch(org.apache.bcel.generic.ClassGen clazz)
Returns bytecode which will throw a NullPointerException, but it will catch the NPE. |
org.apache.bcel.generic.MethodGen |
mgSelect(org.apache.bcel.generic.ClassGen clazz)
Generates bytecode for a switch statement: |
org.apache.bcel.generic.MethodGen |
mgWhile(org.apache.bcel.generic.ClassGen clazz)
Generates code for a while loop. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static ClassFactory getInstance()
XXX Is there any benefit to this being a singleton?
public java.io.InputStream getResourceAsStream(java.lang.String resName)
resName
- Name of the class to be synthesized.public org.apache.bcel.generic.ClassGen makeClass(java.lang.String className, java.lang.String fileName)
Methods available at this time are:
className
- Name of the class to be constructed.fileName
- Associated file name (??? XXX)public org.apache.bcel.generic.MethodGen makeConstructor(org.apache.bcel.generic.ClassGen clazz)
clazz
- Template for the class being synthesized.
public org.apache.bcel.generic.MethodGen makeMethod(org.apache.bcel.generic.ClassGen clazz)
clazz
- Template for the class being produced.
public org.apache.bcel.generic.MethodGen mgDefault(org.apache.bcel.generic.ClassGen clazz)
public int runTest( int x ) { return 2; }
public org.apache.bcel.generic.MethodGen mgIfThen(org.apache.bcel.generic.ClassGen clazz)
public int runTest( int x ) { if (x > 0) { return 3; } else { return 5; } }
public org.apache.bcel.generic.MethodGen mgNPENoCatch(org.apache.bcel.generic.ClassGen clazz)
public int runTest(int x) { null.runTest( 0 ); return 0; }
public org.apache.bcel.generic.MethodGen mgNPEWithCatch(org.apache.bcel.generic.ClassGen clazz)
try { null.runTest( 0 ); return -1; } catch (NullPointerException npe) { return 3; }
public org.apache.bcel.generic.MethodGen mgSelect(org.apache.bcel.generic.ClassGen clazz)
int runTest (int x) { switch (x) { case 1: return 1; case 2: return 3; case 3: return 5; default: return 2; } }
public org.apache.bcel.generic.MethodGen mgWhile(org.apache.bcel.generic.ClassGen clazz)
int runTest(int x) { while (x > 0) { x --; } return x; }
The actual bytecode produced is:
Label | Instruction | Stack |
---|---|---|
ILOAD | _ -> I | |
if: | DUP | I -> II |
IFLE (ret) | II -> I | |
loop: | ICONST_1 | I -> II |
ISUB | II -> I | |
GOTO (if) | I -> I | |
ret: | IRETURN | I -> _ |
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |