public class Javac extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Javac.CtFieldWithInit |
| Modifier and Type | Field and Description |
|---|---|
static String |
param0Name |
static String |
proceedName |
static String |
resultVarName |
| Constructor and Description |
|---|
Javac(Bytecode b,
CtClass thisClass)
Constructs a compiler.
|
Javac(CtClass thisClass)
Constructs a compiler.
|
| Modifier and Type | Method and Description |
|---|---|
CtMember |
compile(String src)
Compiles a method, constructor, or field declaration
to a class.
|
Bytecode |
compileBody(CtBehavior method,
String src)
Compiles a method (or constructor) body.
|
void |
compileExpr(ASTree e)
Compiles an exression.
|
void |
compileExpr(String src)
Compiles an exression.
|
void |
compileStmnt(String src)
Compiles a statement (or a block).
|
Bytecode |
getBytecode()
Returns the produced bytecode.
|
static ASTree |
parseExpr(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(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(String target,
String method)
Prepares to use $proceed().
|
int |
recordReturnType(CtClass type,
boolean useResultVar)
Prepares to use cast $r, $w, $_, and $type.
|
void |
recordSpecialProceed(String target,
String classname,
String methodname,
String descriptor,
int methodIndex)
Prepares to use $proceed() representing a private/super's method.
|
void |
recordStaticProceed(String targetClass,
String method)
Prepares to use $proceed() representing a static method.
|
void |
recordType(CtClass t)
Prepares to use $type.
|
int |
recordVariable(CtClass type,
String name)
Makes the given variable available.
|
void |
setMaxLocals(int max)
Sets
maxLocals to max. |
public static final String param0Name
public static final String resultVarName
public static final String proceedName
public Javac(CtClass thisClass)
thisClass - the class that a compiled method/field
belongs to.public Bytecode getBytecode()
public CtMember compile(String src) throws CompileError
In a method or constructor body, $0, $1, ... and $_ are not available.
CtMethod, CtConstructor,
or CtField object.CompileErrorrecordProceed(String,String)public Bytecode compileBody(CtBehavior method, String src) throws CompileError
src - a single statement or a block.
If null, this method produces a body returning zero or null.CompileErrorpublic boolean recordLocalVariables(CodeAttribute ca, int pc) throws CompileError
pc - program counter (>= 0)CompileErrorpublic boolean recordParamNames(CodeAttribute ca, int numOfLocalVars) throws CompileError
numOfLocalVars - the number of local variables used
for storing the parameters.CompileErrorpublic 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,...
CompileErrorpublic int recordParams(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,...
use0 - true if $0 is used.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.CompileErrorpublic 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.CompileErrorrecordType(CtClass)public void recordType(CtClass t)
t - the type represented by $type.public int recordVariable(CtClass type, String name) throws CompileError
type - variable typename - variable nameCompileErrorpublic void recordProceed(String target, String method) throws CompileError
target - an expression specifying the target object.
if null, "this" is the target.method - the method name.CompileErrorpublic void recordStaticProceed(String targetClass, String method) throws CompileError
targetClass - the fully-qualified dot-separated name
of the class declaring the method.method - the method name.CompileErrorpublic void recordSpecialProceed(String target, String classname, String methodname, String descriptor, int methodIndex) 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.CompileErrorpublic void recordProceed(ProceedHandler h)
public void compileStmnt(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.
CompileErrorpublic void compileExpr(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.
CompileErrorpublic static ASTree parseExpr(String src, SymbolTable st) throws CompileError
CompileErrorpublic 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.
CompileErrorCopyright © 2016 Shigeru Chiba, www.javassist.org. All Rights Reserved.