Class ConstantPoolGeneration

java.lang.Object
mockit.asm.constantPool.ConstantPoolGeneration

public final class ConstantPoolGeneration extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @org.checkerframework.checker.index.qual.NonNegative int
    Adds the given internal name to typeTable 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 to typeTable 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
     
    getUninitializedItemValue(@org.checkerframework.checker.index.qual.NonNegative int typeTableIndex)
     
    @org.checkerframework.checker.index.qual.NonNegative int
    newClass(String internalName)
    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.
    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.
    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
    newUTF8(String value)
    Adds an UTF8 string to the constant pool of the class being built.
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConstantPoolGeneration

      public ConstantPoolGeneration()
  • Method Details

    • newUTF8

      public @org.checkerframework.checker.index.qual.NonNegative int newUTF8(@NonNull String value)
      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

      @NonNull public StringItem newClassItem(@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:
      a new or already existing class reference item.
    • newMethodHandleItem

      @NonNull public MethodHandleItem newMethodHandleItem(@NonNull MethodHandle methodHandle)
      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 class
      name - the field's name
      desc - 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 class
      name - the method's name
      desc - the method's descriptor
      itf - true if owner is an interface
      Returns:
      a new or already existing method reference item
    • newInteger

      @NonNull public IntItem newInteger(int value)
      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

      @NonNull public FloatItem newFloat(float value)
      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

      @NonNull public LongItem newLong(long value)
      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

      @NonNull public DoubleItem newDouble(double value)
      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

      @NonNull public Item newConstItem(@NonNull Object cst)
      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.
      Parameters:
      cst - the value of the constant to be added to the constant pool, which must be an Integer, a Float, a Long, a Double, a String, or a JavaType
      Returns:
      a new or already existing constant item with the given value
    • addNormalType

      public @org.checkerframework.checker.index.qual.NonNegative int addNormalType(@NonNull String type)
      Adds the given internal name to typeTable 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 to typeTable 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 table
      offset - 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 calls getCommonSuperClass(java.lang.String, java.lang.String) and caches the result in the items hash table to speedup future calls with the same parameters.
      Parameters:
      type1 - index of an internal name in typeTable
      type2 - index of an internal name in typeTable
      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

      public void put(@NonNull ByteVector out)
    • 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)