Top Inners Fields Constructors Methods
javassist.compiler

public Class Javac

extends Object
Class Inheritance
Imports
javassist.CannotCompileException, .CtBehavior, .CtClass, .CtConstructor, .CtField, .CtMember, .CtMethod, .CtPrimitiveType, .Modifier, .NotFoundException, javassist.bytecode.BadBytecode, .Bytecode, .CodeAttribute, .LocalVariableAttribute, .Opcode, javassist.compiler.ast.ASTList, .ASTree, .CallExpr, .Declarator, .Expr, .FieldDecl, .Member, .MethodDecl, .Stmnt, .Symbol

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private Bytecode
pack-priv JvstCodeGen
public static final String
public static final String
public static final String
pack-priv SymbolTable

Constructor Summary

AccessConstructor and Description
public
Javac(CtClass
the class that a compiled method/field belongs to.
thisClass
)

Constructs a compiler.

public
Javac(Bytecode b, CtClass
the class that a compiled method/field belongs to.
thisClass
)

Constructs a compiler.

Method Summary

Modifier and TypeMethod and Description
public CtMember

Returns:

a CtMethod, CtConstructor, or CtField object.
compile
(String src)

Compiles a method, constructor, or field declaration to a class.

public Bytecode
compileBody(CtBehavior method, String
a single statement or a block. If null, this method produces a body returning zero or null.
src
)

Compiles a method (or constructor) body.

public void
compileExpr(String src)

Compiles an exression.

public void
compileExpr(ASTree e)

Compiles an exression.

private CtField
private CtBehavior
public void
compileStmnt(String src)

Compiles a statement (or a block).

public Bytecode
getBytecode()

Returns the produced bytecode.

private static void
public static ASTree
parseExpr(String src, SymbolTable st)

Parsers an expression.

public boolean

Returns:

false if the CodeAttribute does not include a LocalVariableAttribute.
recordLocalVariables
(CodeAttribute ca, int
program counter (>= 0)
pc
)

Records local variables available at the specified program counter.

public boolean

Returns:

false if the CodeAttribute does not include a LocalVariableAttribute.
recordParamNames
(CodeAttribute ca, int
the number of local variables used for storing the parameters.
numOfLocalVars
)

Records parameter names if the LocalVariableAttribute is available.

public int
recordParams(CtClass[] params, boolean isStatic)

Makes variables $0 (this), $1, $2, ..., and $args represent method parameters.

public int
recordParams(String
the type of $0 (it can be null if use0 is false). It is used as the name of the type represented by $class.
target
,
CtClass[] params, boolean
true if $0 is used.
use0
,
int
the register number of $0 (use0 is true) or $1 (otherwise).
varNo
,
boolean
true if the method in which the compiled bytecode is embedded is static.
isStatic
)

Makes variables $0, $1, $2, ..., and $args represent method parameters.

public void
recordProceed(String
an expression specifying the target object. if null, "this" is the target.
target
,
String
the method name.
method
)

Prepares to use $proceed().

public void
recordProceed(ProceedHandler h)

Prepares to use $proceed().

public int

Returns:

-1 or the variable index assigned to $_.
recordReturnType
(CtClass
the return type.
type
,
boolean
true if $_ is used.
useResultVar
)

Prepares to use cast $r, $w, $_, and $type.

public void
recordSpecialProceed(String
an expression specifying the target object. if null, "this" is the target.
target
,
final String
the class name declaring the method.
classname
,
final String
the method name.
methodname
,
final String
the method descriptor.
descriptor
,
final int methodIndex)

Prepares to use $proceed() representing a private/super's method.

public void
recordStaticProceed(String
the fully-qualified dot-separated name of the class declaring the method.
targetClass
,
String
the method name.
method
)

Prepares to use $proceed() representing a static method.

public void
recordType(CtClass
the type represented by $type.
t
)

Prepares to use $type.

public int
recordVariable(CtClass
variable type
type
,
String
variable name
name
)

Makes the given variable available.

public void
setMaxLocals(int max)

Sets maxLocals to max.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytecodeback to summary
private Bytecode bytecode
genback to summary
pack-priv JvstCodeGen gen
param0Nameback to summary
public static final String param0Name
proceedNameback to summary
public static final String proceedName
resultVarNameback to summary
public static final String resultVarName
stableback to summary
pack-priv SymbolTable stable

Constructor Detail

Javacback to summary
public Javac(CtClass thisClass)

Constructs a compiler.

Parameters
thisClass:CtClass

the class that a compiled method/field belongs to.

Javacback to summary
public Javac(Bytecode b, CtClass thisClass)

Constructs a compiler. The produced bytecode is stored in the Bytecode object specified by b.

Parameters
thisClass:CtClass

the class that a compiled method/field belongs to.

Method Detail

compileback to summary
public CtMember compile(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:CtMember

a CtMethod, CtConstructor, or CtField object.

See Also
recordProceed(String, String)
compileBodyback to summary
public Bytecode compileBody(CtBehavior method, String src) throws CompileError

Compiles a method (or constructor) body.

Parameters
src:String

a single statement or a block. If null, this method produces a body returning zero or null.

compileExprback to summary
public void compileExpr(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.

compileExprback to summary
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.

compileFieldback to summary
private CtField compileField(FieldDecl fd) throws CompileError, CannotCompileException
compileMethodback to summary
private CtBehavior compileMethod(Parser p, MethodDecl md) throws CompileError
compileStmntback to summary
public void compileStmnt(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 might not be accessible within that source text. Fields and method parameters ($0, $1, ..) are available.

getBytecodeback to summary
public Bytecode getBytecode()

Returns the produced bytecode.

makeDefaultBodyback to summary
private static void makeDefaultBody(Bytecode b, CtClass type)
parseExprback to summary
public static ASTree parseExpr(String src, SymbolTable st) throws CompileError

Parsers an expression.

recordLocalVariablesback to summary
public boolean recordLocalVariables(CodeAttribute ca, int pc) throws CompileError

Records local variables available at the specified program counter. If the LocalVariableAttribute is not available, this method does not record any local variable. It only returns false.

Parameters
pc:int

program counter (>= 0)

Returns:boolean

false if the CodeAttribute does not include a LocalVariableAttribute.

recordParamNamesback to summary
public boolean recordParamNames(CodeAttribute ca, int numOfLocalVars) throws CompileError

Records parameter names if the LocalVariableAttribute is available. It returns false unless the LocalVariableAttribute is available.

Parameters
numOfLocalVars:int

the number of local variables used for storing the parameters.

Returns:boolean

false if the CodeAttribute does not include a LocalVariableAttribute.

recordParamsback to summary
public int recordParams(CtClass[] 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. maxLocals is updated to include $0,...

recordParamsback to summary
public int recordParams(String target, CtClass[] 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). $class is also made available.

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,...

Parameters
target:String

the type of $0 (it can be null if use0 is false). It is used as the name of the type represented by $class.

use0:boolean

true if $0 is used.

varNo:int

the register number of $0 (use0 is true) or $1 (otherwise).

isStatic:boolean

true if the method in which the compiled bytecode is embedded is static.

recordProceedback to summary
public void recordProceed(String target, String method) throws CompileError

Prepares to use $proceed(). If the return type of $proceed() is void, null is pushed on the stack.

Parameters
target:String

an expression specifying the target object. if null, "this" is the target.

method:String

the method name.

recordProceedback to summary
public void recordProceed(ProceedHandler h)

Prepares to use $proceed().

recordReturnTypeback to summary
public int recordReturnType(CtClass type, boolean useResultVar) throws CompileError

Prepares to use cast $r, $w, $_, and $type. $type is made to represent the specified return 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
type:CtClass

the return type.

useResultVar:boolean

true if $_ is used.

Returns:int

-1 or the variable index assigned to $_.

See Also
recordType(CtClass)
recordSpecialProceedback to summary
public void recordSpecialProceed(String target, final String classname, final String methodname, final String descriptor, final int methodIndex) throws CompileError

Prepares to use $proceed() representing a private/super's method. If the return type of $proceed() is void, null is pushed on the stack. This method is for methods invoked by INVOKESPECIAL.

Parameters
target:String

an expression specifying the target object. if null, "this" is the target.

classname:String

the class name declaring the method.

methodname:String

the method name.

descriptor:String

the method descriptor.

recordStaticProceedback to summary
public void recordStaticProceed(String targetClass, String method) throws CompileError

Prepares to use $proceed() representing a static method. If the return type of $proceed() is void, null is pushed on the stack.

Parameters
targetClass:String

the fully-qualified dot-separated name of the class declaring the method.

method:String

the method name.

recordTypeback to summary
public void recordType(CtClass t)

Prepares to use $type. Note that recordReturnType() overwrites the value of $type.

Parameters
t:CtClass

the type represented by $type.

recordVariableback to summary
public int recordVariable(CtClass type, String name) throws CompileError

Makes the given variable available.

Parameters
type:CtClass

variable type

name:String

variable name

setMaxLocalsback to summary
public void setMaxLocals(int max)

Sets 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.

javassist.compiler back to summary

public Class Javac.CtFieldWithInit

extends CtField
Class Inheritance

Field Summary

Modifier and TypeField and Description
private ASTree
Inherited from javassist.CtField:
fieldInfo

Constructor Summary

AccessConstructor and Description
pack-priv
CtFieldWithInit(CtClass type, String name, CtClass declaring)

Method Summary

Modifier and TypeMethod and Description
protected ASTree
protected void
Inherited from javassist.CtField:
extendToStringgetAnnotationgetAnnotationsgetAttributegetAvailableAnnotationsgetConstantValuegetDeclaringClassgetFieldInfogetFieldInfo2getGenericSignaturegetModifiersgetNamegetSignaturegetTypehasAnnotationmakesetAttributesetGenericSignaturesetModifierssetNamesetTypetoString

Field Detail

initback to summary
private ASTree init

Constructor Detail

CtFieldWithInitback to summary
pack-priv CtFieldWithInit(CtClass type, String name, CtClass declaring) throws CannotCompileException

Method Detail

getInitASTback to summary
protected ASTree getInitAST()

Overrides javassist.CtField.getInitAST.

Annotations
@Override
setInitback to summary
protected void setInit(ASTree i)