APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.org.apache.bcel.internal.generic

public Class InstructionFactory

extends Object
Class Inheritance
Imports
com.sun.org.apache.bcel.internal.Const

Instances of this class may be used, e.g., to generate typed versions of instructions. Its main purpose is to be used as the byte code generating backend of a compiler. You can subclass it to add your own create methods.

Note

The static createXXX methods return singleton instances from the InstructionConst class.

See Also
Const, InstructionConst

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final InstructionFactory.MethodObject[]
protected ClassGen
cg

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter
protected ConstantPoolGen
cp

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter
private static final String
private static final String[]
SHORT_NAMES

These must agree with the order of Constants.T_CHAR through T_LONG.

Constructor Summary

AccessConstructor and Description
public
InstructionFactory(final ClassGen cg)

Initialize with ClassGen object

public
public
InstructionFactory(final ConstantPoolGen cp)

Initialize just with ConstantPoolGen object

Method Summary

Modifier and TypeMethod and Description
public Instruction
createAppend(final Type type)

public static ArrayInstruction
createArrayLoad(final Type
type of elements of array, i.e., array.getElementType()
type
)

public static ArrayInstruction
createArrayStore(final Type
type of elements of array, i.e., array.getElementType()
type
)

private static ArithmeticInstruction
createBinaryDoubleOp(final char op)

private static ArithmeticInstruction
createBinaryFloatOp(final char op)

private static ArithmeticInstruction
createBinaryIntOp(final char first, final String op)

private static ArithmeticInstruction
createBinaryLongOp(final char first, final String op)

Create an invokedynamic instruction.

public static ArithmeticInstruction
createBinaryOperation(final String
operation, such as "+", "*", "<<", etc.
op
,
final Type type)

Create binary operation for simple basic types, such as int and float.

public static BranchInstruction
createBranchInstruction(final short opcode, final InstructionHandle target)

Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.

public Instruction
createCast(final Type srcType, final Type destType)

Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., if the operands are basic types and CHECKCAST if they are reference types.

public CHECKCAST
public Instruction
createConstant(final Object
must be of type Number, Boolean, Character or String
value
)

Uses PUSH to push a constant value onto the stack.

public static StackInstruction
createDup(final int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public static StackInstruction
createDup_1(final int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public static StackInstruction
createDup_2(final int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public FieldInstruction
createFieldAccess(final String
name of the accessed class
className
,
final String
name of the referenced field
name
,
final Type
type of field
type
,
final short
how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
kind
)

Create a field instruction.

public GETFIELD
createGetField(final String className, final String name, final Type t)

public GETSTATIC
createGetStatic(final String className, final String name, final Type t)

public INSTANCEOF
private InvokeInstruction
createInvoke(final InstructionFactory.MethodObject m, final short kind)

public InvokeInstruction
createInvoke(final String
name of the called class
className
,
final String
name of the called method
name
,
final Type
return type of method
retType
,
final Type[]
argument types of method
argTypes
,
final short
how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL
kind
)

Create an invoke instruction.

public InvokeInstruction

Returns:

A new InvokeInstruction.
createInvoke
(final String
name of the called class
className
,
final String
name of the called method
name
,
final Type
return type of method
retType
,
final Type[]
argument types of method
argTypes
,
final short
how to invoke: INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL
kind
,
final boolean
force use of InterfaceMethodref
useInterface
)

Create an invoke instruction.

public static LocalVariableInstruction
createLoad(final Type type, final int
index of local variable
index
)

public NEW
public NEW
createNew(final String s)

public Instruction

Returns:

an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction
createNewArray
(final Type t, final short dim)

Create new array of given size and type.

public static Instruction
createNull(final Type type)

Create "null" value for reference types, 0 for basic types like int

public static StackInstruction
createPop(final int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public InstructionList
createPrintln(final String
the string to print
s
)

Create a call to the most popular System.out.println() method.

public PUTFIELD
createPutField(final String className, final String name, final Type t)

public PUTSTATIC
createPutStatic(final String className, final String name, final Type t)

public static ReturnInstruction
createReturn(final Type type)

Create typed return

public static LocalVariableInstruction
createStore(final Type type, final int
index of local variable
index
)

public static Instruction
createThis()

Create reference to 'this'

public ClassGen
public ConstantPoolGen
private static boolean
isString(final Type type)

public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

APPENDback to summary
private static final String APPEND
APPEND_METHOD_OBJECTSback to summary
private static final InstructionFactory.MethodObject[] APPEND_METHOD_OBJECTS
cgback to summary
protected ClassGen cg

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated
cpback to summary
protected ConstantPoolGen cp

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated
FQCN_STRING_BUFFERback to summary
private static final String FQCN_STRING_BUFFER
SHORT_NAMESback to summary
private static final String[] SHORT_NAMES

These must agree with the order of Constants.T_CHAR through T_LONG.

Constructor Detail

InstructionFactoryback to summary
public InstructionFactory(final ClassGen cg)

Initialize with ClassGen object

InstructionFactoryback to summary
public InstructionFactory(final ClassGen cg, final ConstantPoolGen cp)
InstructionFactoryback to summary
public InstructionFactory(final ConstantPoolGen cp)

Initialize just with ConstantPoolGen object

Method Detail

createAppendback to summary
public Instruction createAppend(final Type type)
createArrayLoadback to summary
public static ArrayInstruction createArrayLoad(final Type type)
Parameters
type:Type

type of elements of array, i.e., array.getElementType()

createArrayStoreback to summary
public static ArrayInstruction createArrayStore(final Type type)
Parameters
type:Type

type of elements of array, i.e., array.getElementType()

createBinaryDoubleOpback to summary
private static ArithmeticInstruction createBinaryDoubleOp(final char op)
createBinaryFloatOpback to summary
private static ArithmeticInstruction createBinaryFloatOp(final char op)
createBinaryIntOpback to summary
private static ArithmeticInstruction createBinaryIntOp(final char first, final String op)
createBinaryLongOpback to summary
private static ArithmeticInstruction createBinaryLongOp(final char first, final String op)

Create an invokedynamic instruction.

See Also
Const
createBinaryOperationback to summary
public static ArithmeticInstruction createBinaryOperation(final String op, final Type type)

Create binary operation for simple basic types, such as int and float.

Parameters
op:String

operation, such as "+", "*", "<<", etc.

createBranchInstructionback to summary
public static BranchInstruction createBranchInstruction(final short opcode, final InstructionHandle target)

Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. For those you should use the SWITCH compound instruction.

createCastback to summary
public Instruction createCast(final Type srcType, final Type destType)

Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., if the operands are basic types and CHECKCAST if they are reference types.

createCheckCastback to summary
public CHECKCAST createCheckCast(final ReferenceType t)
createConstantback to summary
public Instruction createConstant(final Object value)

Uses PUSH to push a constant value onto the stack.

Parameters
value:Object

must be of type Number, Boolean, Character or String

createDupback to summary
public static StackInstruction createDup(final int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createDup_1back to summary
public static StackInstruction createDup_1(final int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createDup_2back to summary
public static StackInstruction createDup_2(final int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createFieldAccessback to summary
public FieldInstruction createFieldAccess(final String className, final String name, final Type type, final short kind)

Create a field instruction.

Parameters
className:String

name of the accessed class

name:String

name of the referenced field

type:Type

type of field

kind:short

how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC

See Also
Const
createGetFieldback to summary
public GETFIELD createGetField(final String className, final String name, final Type t)
createGetStaticback to summary
public GETSTATIC createGetStatic(final String className, final String name, final Type t)
createInstanceOfback to summary
public INSTANCEOF createInstanceOf(final ReferenceType t)
createInvokeback to summary
private InvokeInstruction createInvoke(final InstructionFactory.MethodObject m, final short kind)
createInvokeback to summary
public InvokeInstruction createInvoke(final String className, final String name, final Type retType, final Type[] argTypes, final short kind)

Create an invoke instruction. (Except for invokedynamic.)

Parameters
className:String

name of the called class

name:String

name of the called method

retType:Type

return type of method

argTypes:Type[]

argument types of method

kind:short

how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL

See Also
Const
createInvokeback to summary
public InvokeInstruction createInvoke(final String className, final String name, final Type retType, final Type[] argTypes, final short kind, final boolean useInterface)

Create an invoke instruction. (Except for invokedynamic.)

Parameters
className:String

name of the called class

name:String

name of the called method

retType:Type

return type of method

argTypes:Type[]

argument types of method

kind:short

how to invoke: INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL

useInterface:boolean

force use of InterfaceMethodref

Returns:InvokeInstruction

A new InvokeInstruction.

Since
6.5.0
createLoadback to summary
public static LocalVariableInstruction createLoad(final Type type, final int index)
Parameters
index:int

index of local variable

createNewback to summary
public NEW createNew(final ObjectType t)
createNewback to summary
public NEW createNew(final String s)
createNewArrayback to summary
public Instruction createNewArray(final Type t, final short dim)

Create new array of given size and type.

Returns:Instruction

an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction

createNullback to summary
public static Instruction createNull(final Type type)

Create "null" value for reference types, 0 for basic types like int

createPopback to summary
public static StackInstruction createPop(final int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createPrintlnback to summary
public InstructionList createPrintln(final String s)

Create a call to the most popular System.out.println() method.

Parameters
s:String

the string to print

createPutFieldback to summary
public PUTFIELD createPutField(final String className, final String name, final Type t)
createPutStaticback to summary
public PUTSTATIC createPutStatic(final String className, final String name, final Type t)
createReturnback to summary
public static ReturnInstruction createReturn(final Type type)

Create typed return

createStoreback to summary
public static LocalVariableInstruction createStore(final Type type, final int index)
Parameters
index:int

index of local variable

createThisback to summary
public static Instruction createThis()

Create reference to 'this'

getClassGenback to summary
public ClassGen getClassGen()
getConstantPoolback to summary
public ConstantPoolGen getConstantPool()
isStringback to summary
private static boolean isString(final Type type)
setClassGenback to summary
public void setClassGen(final ClassGen c)
setConstantPoolback to summary
public void setConstantPool(final ConstantPoolGen c)
com.sun.org.apache.bcel.internal.generic back to summary

private final Class InstructionFactory.MethodObject

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.bcel.internal.generic.InstructionFactory.MethodObject

Field Summary

Modifier and TypeField and Description
pack-priv final Type[]
pack-priv final String
pack-priv final String
pack-priv final Type

Constructor Summary

AccessConstructor and Description
pack-priv
MethodObject(final String c, final String n, final Type r, final Type[] a)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

argTypesback to summary
pack-priv final Type[] argTypes
classNameback to summary
pack-priv final String className
nameback to summary
pack-priv final String name
resultTypeback to summary
pack-priv final Type resultType

Constructor Detail

MethodObjectback to summary
pack-priv MethodObject(final String c, final String n, final Type r, final Type[] a)