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

      void read(DataInputStream in) throws IOException
      decodes a ConstantPool and it's constants from a data stream.
      Throws:
      IOException
    • inbounds

      private boolean inbounds(int cpx)
      bounds-check a CP index.
    • 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 Java Module name, 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.

    • 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

    • 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.
    • print

      public void print() throws IOException
      prints the entire constant pool.
      Specified by:
      print in interface Printable
      Overrides:
      print in class Indenter
      Throws:
      IOException
    • getTagPadding

      private int getTagPadding()
    • getCommentPadding

      private int getCommentPadding()
    • getCommentOffset

      public int getCommentOffset()
      Overrides:
      getCommentOffset in class Indenter
      Returns:
      the common offset of comments for printing methods
    • getIssues

      public List<IOException> getIssues()