Class ConstantPool

java.lang.Object
org.openjdk.asmtools.jdis.Indenter
org.openjdk.asmtools.jdis.ConstantPool
All Implemented Interfaces:
Printable

public class ConstantPool extends Indenter
Class representing the Constant Pool
  • Field Details

  • Constructor Details

    • ConstantPool

      public ConstantPool(ClassData cd)
    • ConstantPool

      public ConstantPool(ClassData classData, int size)
  • Method Details

    • setPrintTAG

      public void setPrintTAG(boolean value)
    • getPrintedTAG

      public String getPrintedTAG(ConstantPool.TAG tag)
    • size

      public int size()
    • inRange

      public boolean inRange(int value)
    • read

      decodes a ConstantPool and it's constants from a data stream.
      Throws:
      IOException
    • getConst

      public ConstantPool.Constant getConst(int cpx)
      Public getter - Safely gets a Constant from the CP at a given index.
    • getString

      public String getString(int cpx, Function<Integer,String> funcGetDefaultString)
      Safely gets the string representation of a ConstantUTF8 from the CP at a given index.

      Returns either the UTF8 string, or a default ConstantUTF8 built by CP index with the function funcGetDefaultString like: index-> "#" + index

    • getModuleName

      public String getModuleName(int cpx, Function<Integer,String> funcGetDefaultModuleName)
      Safely gets the string representation of a ConstantModule from the CP at a given index.

      Returns either the Java Module name, or a default class name built by CP index with the function funcGetDefaultModuleName like: index-> "#" + index

    • getModuleName

      public String getModuleName(int cpx)
    • getPackageName

      public String getPackageName(int cpx, Function<Integer,String> funcGetDefaultPackageName)
      Public string val - Safely gets the string representation of a ConstantPackage from the CP at a given index.

      Returns either the Java Package name, or a default class name built by CP index with the function funcGetDefaultPackageName like: index-> "#" + index

    • getPackageName

      public String getPackageName(int cpx)
    • getName

      public String getName(int cpx)
      Safely gets a Java name from a ConstantUTF8 from the CP at a given index.

      Returns either null (if invalid), or the Java name value of the UTF8

    • getClassName

      public String getClassName(int cpx)
      Safely gets a Java class name from a ConstantClass from the CP at a given index.

      Returns either the Java class name, or a CP index reference string.

    • getMethodName

      public String getMethodName(int cpx)
    • getFieldNameTypeAsString

      public String getFieldNameTypeAsString(int cpx)
      Gets a string representation of the constant_pool entry at the specified index, pointing to a CONSTANT_NameAndType_info structure with a field descriptor.
      Parameters:
      cpx - the constant_pool index pointing to CONSTANT_NameAndType_info
      Returns:
      a string presentation of the CONSTANT_NameAndType_info structure
    • referredBy

      public boolean referredBy(int cpx, ConstantPool.TAG... tags)
    • getJavaClassName

      public String getJavaClassName(int cpx, String formatString)
      Safely gets a Java class name from a ConstantClass from the CP at a given index.

      Returns either the Java class name, or a message string formatted by cpx: formatString.formatted(cpx)

    • getClassName

      public String getClassName(int cpx, Function<Integer,String> funcGetDefaultClassName)
      Safely gets a Java class name from a ConstantClass from the CP at a given index.

      Returns either the Java class name, or a default class name built by CP index with the function funcGetDefaultClassName like: index-> "#" + index

    • getConstantOfClassName

      public ConstantPool.Constant getConstantOfClassName(int cpx)
    • getClassName

      public String getClassName(ConstantPool.CPX2 classConst)
      Safely gets a Java class name from a ConstantClass from a CPX2 constant pool object. (eg. Method/Field/Interface Ref)

      Returns either the Java class name, or a CP index reference string.

    • getClassName

      public String getClassName(ConstantPool.CPX classConst)
      Safely gets a Java class name from a ConstantClass from a CPX constant pool object. (eg. Class Ref)

      Returns either the Java class name, or a CP index reference string.

    • _getClassName

      private String _getClassName(int nameIndex)
      Helper for getting class name. It checks ConstantPool bounds, does name conversion.
    • getShortClassName

      public String getShortClassName(String className, String packageName)
      Shortens a class name (if the class is in the given package). Works with a string-encoded classname.
      Parameters:
      className - fully qualified name of the class
      packageName - the package
    • getShortClassName

      public String getShortClassName(int cpx, String packageName)
      Shortens a class name (if the class is in the given package). Works with a CP index to a ConstantClass.
      Parameters:
      cpx - the Constant Pool index to a CONSTANT_Class_info
      packageName - the package
    • decodeClassDescriptor

      public String decodeClassDescriptor(int cpx)
      Pulls the class name out of a string (at the CP index). (drops any array descriptors, and the class descriptors ("L" and ";")
    • subtagToString

      private String subtagToString(int subtag)
      Getter that safely gets the string descriptor of a subtag
    • StringValue

      public String StringValue(int cpx)
      Safely gets the string value of any Constant at any CP index.
    • ConstantStrValue

      public String ConstantStrValue(int cpx)
      Safely gets the string value of any Constant at any CP index. This string is either a Constant's String value or a CP index reference string. The Constant string has a tag descriptor in the beginning.
    • isTableOutput

      public boolean isTableOutput()
      Overrides:
      isTableOutput in class Indenter
    • jasmPrint

      protected void jasmPrint()
      Overrides:
      jasmPrint in class Indenter
    • tablePrint

      protected void tablePrint()
      Overrides:
      tablePrint in class Indenter
    • InitializePrintData

      protected ConstantPool InitializePrintData()
      Initialize printing data once the pool was read. Prepare offsets, paddings, etc. needed for printing
    • getCommentPadding

      public int getCommentPadding()
    • getIssues

      public List<IOException> getIssues()
    • getCPX2

      public ConstantPool.CPX2 getCPX2(ConstantPool.TAG tag)
    • CheckEntryType

      public boolean CheckEntryType(int cpIndex, ConstantPool.TAG... tags)
    • getTag

      public ConstantPool.TAG getTag(int cpIndex)