classUtils.javassist.compiler
Class Javac

java.lang.Object
  extended by classUtils.javassist.compiler.Javac

public class Javac
extends java.lang.Object


Nested Class Summary
static class Javac.CtFieldWithInit
           
 
Field Summary
static java.lang.String param0Name
           
static java.lang.String proceedName
           
static java.lang.String resultVarName
           
 
Constructor Summary
Javac(Bytecode b, CompileTimeClass thisClass)
          Constructs a compiler.
Javac(CompileTimeClass thisClass)
          Constructs a compiler.
 
Method Summary
 CtMember compile(java.lang.String src)
          Compiles a method, constructor, or field declaration to a class.
 Bytecode compileBody(CtBehavior method, java.lang.String src)
          Compiles a method (or constructor) body.
 void compileExpr(ASTree e)
          Compiles an exression.
 void compileExpr(java.lang.String src)
          Compiles an exression.
 void compileStmnt(java.lang.String src)
          Compiles a statement (or a block).
 Bytecode getBytecode()
          Returns the produced bytecode.
 void recordParams(CompileTimeClass[] params, boolean isStatic)
          Makes variables $0 (this), $1, $2, ..., and $args represent method parameters.
 void recordParams(java.lang.String target, CompileTimeClass[] params, boolean use0, int varNo, boolean isStatic)
          Makes variables $0, $1, $2, ..., and $args represent method parameters.
 void recordProceed(ProceedHandler h)
          Prepares to use $proceed().
 void recordProceed(java.lang.String target, java.lang.String method)
          Prepares to use $proceed().
 int recordReturnType(CompileTimeClass type, boolean useResultVar)
          Prepares to use cast $r, $w, $_, and $type.
 void recordType(CompileTimeClass t)
          Prepares to use $type.
 int recordVariable(CompileTimeClass type, java.lang.String name)
          Makes the given variable available.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

param0Name

public static final java.lang.String param0Name
See Also:
Constant Field Values

resultVarName

public static final java.lang.String resultVarName
See Also:
Constant Field Values

proceedName

public static final java.lang.String proceedName
See Also:
Constant Field Values
Constructor Detail

Javac

public Javac(CompileTimeClass thisClass)
Constructs a compiler.

Parameters:
thisClass - the class that a compiled method/field belongs to.

Javac

public Javac(Bytecode b,
             CompileTimeClass thisClass)
Constructs a compiler. The produced bytecode is stored in the Bytecode object specified by b.

Parameters:
thisClass - the class that a compiled method/field belongs to.
Method Detail

getBytecode

public Bytecode getBytecode()
Returns the produced bytecode.


compile

public CtMember compile(java.lang.String src)
                 throws CompileError
Compiles a method, constructor, or field declaration to a class. A field declaration can declare only one field.

In a method or constructor body, $0, $1, ... and $_ are not available.

Returns:
a CtMethod, CtConstructor, or CtField object.
Throws:
CompileError
See Also:
recordProceed(String,String)

compileBody

public Bytecode compileBody(CtBehavior method,
                            java.lang.String src)
                     throws CompileError
Compiles a method (or constructor) body. a single statement or a block. If null, this method produces a body returning zero or null.

Throws:
CompileError

recordParams

public void recordParams(CompileTimeClass[] params,
                         boolean isStatic)
                  throws CompileError
Makes variables $0 (this), $1, $2, ..., and $args represent method parameters. $args represents an array of all the parameters. It also makes $$ available as a parameter list of method call.

This must be called before calling compileStmnt() and compileExpr(). The correct value of isStatic must be recorded before compilation.

Throws:
CompileError

recordParams

public void recordParams(java.lang.String target,
                         CompileTimeClass[] params,
                         boolean use0,
                         int varNo,
                         boolean isStatic)
                  throws CompileError
Makes variables $0, $1, $2, ..., and $args represent method parameters. $args represents an array of all the parameters. It also makes $$ available as a parameter list of method call. $0 can represent a local variable other than THIS (variable 0).

This must be called before calling compileStmnt() and compileExpr(). The correct value of isStatic must be recorded before compilation. true if $0 is used.

Parameters:
varNo - the register number of $0 (use0 is true) or $1 (otherwise).
target - the type of $0 (it can be null if use0 is false).
isStatic - true if the method in which the compiled bytecode is embedded is static.
Throws:
CompileError

recordReturnType

public int recordReturnType(CompileTimeClass type,
                            boolean useResultVar)
                     throws CompileError
Prepares to use cast $r, $w, $_, and $type. It also enables to write a return statement with a return value for void method.

If the return type is void, ($r) does nothing. The type of $_ is java.lang.Object.

Parameters:
useResultVar - true if $_ is used.
Returns:
-1 or the variable index assigned to $_.
Throws:
CompileError

recordType

public void recordType(CompileTimeClass t)
Prepares to use $type. Note that recordReturnType() overwrites the value of $type.


recordVariable

public int recordVariable(CompileTimeClass type,
                          java.lang.String name)
                   throws CompileError
Makes the given variable available.

Parameters:
type - variable type
name - variable name
Throws:
CompileError

recordProceed

public void recordProceed(java.lang.String target,
                          java.lang.String method)
                   throws CompileError
Prepares to use $proceed(). If the return type of $proceed() is void, null is pushed on the stack.

Parameters:
target - an expression specifying the target object. if null, "this" is the target.
method - the method name.
Throws:
CompileError

recordProceed

public void recordProceed(ProceedHandler h)
Prepares to use $proceed().


compileStmnt

public void compileStmnt(java.lang.String src)
                  throws CompileError
Compiles a statement (or a block). recordParams() must be called before invoking this method.

Local variables that are not declared in the compiled source text are not accessible within that source text. Fields and method parameters ($0, $1, ..) are available.

Throws:
CompileError

compileExpr

public void compileExpr(java.lang.String src)
                 throws CompileError
Compiles an exression. recordParams() must be called before invoking this method.

Local variables are not accessible within the compiled source text. Fields and method parameters ($0, $1, ..) are available if recordParams() have been invoked.

Throws:
CompileError

compileExpr

public void compileExpr(ASTree e)
                 throws CompileError
Compiles an exression. recordParams() must be called before invoking this method.

Local variables are not accessible within the compiled source text. Fields and method parameters ($0, $1, ..) are available if recordParams() have been invoked.

Throws:
CompileError