|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavassist.compiler.Javac
public class Javac
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,
CtClass thisClass)
Constructs a compiler. |
|
Javac(CtClass 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. |
static ASTree |
parseExpr(java.lang.String src,
SymbolTable st)
Parsers an expression. |
boolean |
recordLocalVariables(CodeAttribute ca,
int pc)
Records local variables available at the specified program counter. |
boolean |
recordParamNames(CodeAttribute ca,
int numOfLocalVars)
Records parameter names if the LocalVariableAttribute is available. |
int |
recordParams(CtClass[] params,
boolean isStatic)
Makes variables $0 (this), $1, $2, ..., and $args represent method parameters. |
int |
recordParams(java.lang.String target,
CtClass[] 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(CtClass type,
boolean useResultVar)
Prepares to use cast $r, $w, $_, and $type. |
void |
recordSpecialProceed(java.lang.String target,
java.lang.String classname,
java.lang.String methodname,
java.lang.String descriptor)
Prepares to use $proceed() representing a private/super's method. |
void |
recordStaticProceed(java.lang.String targetClass,
java.lang.String method)
Prepares to use $proceed() representing a static method. |
void |
recordType(CtClass t)
Prepares to use $type. |
int |
recordVariable(CtClass type,
java.lang.String name)
Makes the given variable available. |
void |
setMaxLocals(int max)
Sets maxLocals to max . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String param0Name
public static final java.lang.String resultVarName
public static final java.lang.String proceedName
Constructor Detail |
---|
public Javac(CtClass thisClass)
thisClass
- the class that a compiled method/field
belongs to.public Javac(Bytecode b, CtClass thisClass)
Bytecode
object
specified by b
.
thisClass
- the class that a compiled method/field
belongs to.Method Detail |
---|
public Bytecode getBytecode()
public CtMember compile(java.lang.String src) throws CompileError
In a method or constructor body, $0, $1, ... and $_ are not available.
CtMethod
, CtConstructor
,
or CtField
object.
CompileError
recordProceed(String,String)
public Bytecode compileBody(CtBehavior method, java.lang.String src) throws CompileError
CompileError
public boolean recordLocalVariables(CodeAttribute ca, int pc) throws CompileError
pc
- program counter (>= 0)
CompileError
public boolean recordParamNames(CodeAttribute ca, int numOfLocalVars) throws CompileError
numOfLocalVars
- the number of local variables used
for storing the parameters.
CompileError
public int recordParams(CtClass[] params, boolean isStatic) throws CompileError
This must be called before calling compileStmnt()
and
compileExpr()
. The correct value of
isStatic
must be recorded before compilation.
maxLocals
is updated to include $0,...
CompileError
public int recordParams(java.lang.String target, CtClass[] params, boolean use0, int varNo, boolean isStatic) throws CompileError
This must be called before calling compileStmnt()
and
compileExpr()
. The correct value of
isStatic
must be recorded before compilation.
maxLocals
is updated to include $0,...
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).
It is used as the name of the type represented
by $class.isStatic
- true if the method in which the compiled bytecode
is embedded is static.
CompileError
public void setMaxLocals(int max)
maxLocals
to max
.
This method tells the compiler the local variables that have been
allocated for the rest of the code. When the compiler needs
new local variables, the local variables at the index max
,
max + 1
, ... are assigned.
This method is indirectly called by recordParams
.
public int recordReturnType(CtClass type, boolean useResultVar) throws CompileError
If the return type is void, ($r) does nothing. The type of $_ is java.lang.Object.
type
- the return type.useResultVar
- true if $_ is used.
CompileError
recordType(CtClass)
public void recordType(CtClass t)
t
- the type represented by $type.public int recordVariable(CtClass type, java.lang.String name) throws CompileError
type
- variable typename
- variable name
CompileError
public void recordProceed(java.lang.String target, java.lang.String method) throws CompileError
target
- an expression specifying the target object.
if null, "this" is the target.method
- the method name.
CompileError
public void recordStaticProceed(java.lang.String targetClass, java.lang.String method) throws CompileError
targetClass
- the fully-qualified dot-separated name
of the class declaring the method.method
- the method name.
CompileError
public void recordSpecialProceed(java.lang.String target, java.lang.String classname, java.lang.String methodname, java.lang.String descriptor) throws CompileError
target
- an expression specifying the target object.
if null, "this" is the target.classname
- the class name declaring the method.methodname
- the method name.descriptor
- the method descriptor.
CompileError
public void recordProceed(ProceedHandler h)
public void compileStmnt(java.lang.String src) throws CompileError
recordParams()
must be called before invoking
this method.
Local variables that are not declared in the compiled source text might not be accessible within that source text. Fields and method parameters ($0, $1, ..) are available.
CompileError
public void compileExpr(java.lang.String src) throws CompileError
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.
CompileError
public static ASTree parseExpr(java.lang.String src, SymbolTable st) throws CompileError
CompileError
public void compileExpr(ASTree e) throws CompileError
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.
CompileError
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |