Package mockit.asm.constantPool
Class ConstantPoolGeneration
java.lang.Object
mockit.asm.constantPool.ConstantPoolGeneration
Allows the constant pool for a classfile to be created from scratch, when that classfile itself is being generated or
modified from an existing class file.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@org.checkerframework.checker.index.qual.NonNegative int
addNormalType
(String type) Adds the given internal name totypeTable
and returns its index.@org.checkerframework.checker.index.qual.NonNegative int
addUninitializedType
(String type, @org.checkerframework.checker.index.qual.NonNegative int offset) Adds the given "uninitialized" type totypeTable
and returns its index.void
void
copy
(byte[] code, @org.checkerframework.checker.index.qual.NonNegative int off, @org.checkerframework.checker.index.qual.NonNegative int header, Item[] cpItems) createDynamicItem
(int type, String name, String desc, @org.checkerframework.checker.index.qual.NonNegative int bsmIndex) getInternalName
(@org.checkerframework.checker.index.qual.NonNegative int typeTableIndex) getItem
(@org.checkerframework.checker.index.qual.NonNegative int itemHashCode) @org.checkerframework.checker.index.qual.NonNegative int
getMergedType
(@org.checkerframework.checker.index.qual.NonNegative int type1, @org.checkerframework.checker.index.qual.NonNegative int type2) Returns the index of the common super type of the two given types.@org.checkerframework.checker.index.qual.NonNegative int
getSize()
getUninitializedItemValue
(@org.checkerframework.checker.index.qual.NonNegative int typeTableIndex) @org.checkerframework.checker.index.qual.NonNegative int
Adds a class reference to the constant pool of the class being built.newClassItem
(String internalName) Adds a class reference to the constant pool of the class being built.newConstItem
(Object cst) Adds a number or string constant to the constant pool of the class being built.newDouble
(double value) Adds a double to the constant pool of the class being built.newFieldItem
(String owner, String name, String desc) Adds a field reference to the constant pool of the class being built.newFloat
(float value) Adds a float to the constant pool of the class being built.newInteger
(int value) Adds an integer to the constant pool of the class being built.newLong
(long value) Adds a long to the constant pool of the class being built.newMethodHandleItem
(MethodHandle methodHandle) Adds a method handle to the constant pool of the class being built.newMethodItem
(String owner, String name, String desc, boolean itf) Adds a method reference to the constant pool of the class being built.@org.checkerframework.checker.index.qual.NonNegative int
Adds an UTF8 string to the constant pool of the class being built.void
put
(ByteVector out)
-
Constructor Details
-
ConstantPoolGeneration
public ConstantPoolGeneration()
-
-
Method Details
-
newUTF8
Adds an UTF8 string to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
value
- the String value.- Returns:
- the index of a new or already existing UTF8 item.
-
newClass
public @org.checkerframework.checker.index.qual.NonNegative int newClass(@NonNull String internalName) Adds a class reference to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
internalName
- the internal name of the class.- Returns:
- the index of a new or already existing class reference item.
-
newClassItem
Adds a class reference to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
internalName
- the internal name of the class.- Returns:
- a new or already existing class reference item.
-
newMethodHandleItem
Adds a method handle to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Returns:
- a new or an already existing method type reference item.
-
newFieldItem
@NonNull public ClassMemberItem newFieldItem(@NonNull String owner, @NonNull String name, @NonNull String desc) Adds a field reference to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
owner
- the internal name of the field's owner classname
- the field's namedesc
- the field's descriptor- Returns:
- a new or already existing field reference item
-
newMethodItem
@NonNull public ClassMemberItem newMethodItem(@NonNull String owner, @NonNull String name, @NonNull String desc, boolean itf) Adds a method reference to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
owner
- the internal name of the method's owner classname
- the method's namedesc
- the method's descriptoritf
-true
ifowner
is an interface- Returns:
- a new or already existing method reference item
-
newInteger
Adds an integer to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
value
- the int value- Returns:
- a new or already existing int item
-
newFloat
Adds a float to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
value
- the float value- Returns:
- a new or already existing float item
-
newLong
Adds a long to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
value
- the long value- Returns:
- a new or already existing long item
-
newDouble
Adds a double to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item.- Parameters:
value
- the double value- Returns:
- a new or already existing double item
-
newConstItem
Adds a number or string constant to the constant pool of the class being built. Does nothing if the constant pool already contains a similar item. -
addNormalType
Adds the given internal name totypeTable
and returns its index. Does nothing if the type table already contains this internal name.- Parameters:
type
- the internal name to be added to the type table- Returns:
- the index of this internal name in the type table
-
addUninitializedType
public @org.checkerframework.checker.index.qual.NonNegative int addUninitializedType(@NonNull String type, @org.checkerframework.checker.index.qual.NonNegative int offset) Adds the given "uninitialized" type totypeTable
and returns its index. This method is used for UNINITIALIZED types, made of an internal name and a bytecode offset.- Parameters:
type
- the internal name to be added to the type tableoffset
- the bytecode offset of the NEW instruction that created this UNINITIALIZED type value- Returns:
- the index of this internal name in the type table
-
getMergedType
public @org.checkerframework.checker.index.qual.NonNegative int getMergedType(@org.checkerframework.checker.index.qual.NonNegative int type1, @org.checkerframework.checker.index.qual.NonNegative int type2) Returns the index of the common super type of the two given types. This method callsgetCommonSuperClass(java.lang.String, java.lang.String)
and caches the result in theitems
hash table to speedup future calls with the same parameters.- Parameters:
type1
- index of an internal name intypeTable
type2
- index of an internal name intypeTable
- Returns:
- the index of the common super type of the two given types
-
getInternalName
@NonNull public String getInternalName(@org.checkerframework.checker.index.qual.NonNegative int typeTableIndex) -
getUninitializedItemValue
@NonNull public UninitializedTypeTableItem getUninitializedItemValue(@org.checkerframework.checker.index.qual.NonNegative int typeTableIndex) -
getItem
@Nullable public Item getItem(@org.checkerframework.checker.index.qual.NonNegative int itemHashCode) -
getSize
public @org.checkerframework.checker.index.qual.NonNegative int getSize() -
checkConstantPoolMaxSize
public void checkConstantPoolMaxSize() -
put
-
copy
public void copy(@NonNull byte[] code, @org.checkerframework.checker.index.qual.NonNegative int off, @org.checkerframework.checker.index.qual.NonNegative int header, @NonNull Item[] cpItems) -
createDynamicItem
@NonNull public DynamicItem createDynamicItem(int type, @NonNull String name, @NonNull String desc, @org.checkerframework.checker.index.qual.NonNegative int bsmIndex)
-