Class ClassDataItem

All Implemented Interfaces:
Comparable<OffsettedItem>

public final class ClassDataItem extends OffsettedItem
Representation of all the parts of a Dalvik class that are generally "inflated" into an in-memory representation at runtime. Instances of this class are represented in a compact streamable form in a dex file, as opposed to a random-access form.
  • Constructor Details

    • ClassDataItem

      public ClassDataItem(CstType thisClass)
      Constructs an instance. Its sets of members are initially empty.
      Parameters:
      thisClass - non-null; what class this data is for, just for listing generation
  • Method Details

    • itemType

      public ItemType itemType()
      Returns the item type for this instance.
      Specified by:
      itemType in class Item
      Returns:
      non-null; the item type
    • toHuman

      public String toHuman()
      Gets a short human-readable string representing this instance.
      Specified by:
      toHuman in class OffsettedItem
      Returns:
      non-null; the human form
    • isEmpty

      public boolean isEmpty()
      Returns whether this instance is empty.
      Returns:
      true if this instance is empty or false if at least one element has been added to it
    • addStaticField

      public void addStaticField(EncodedField field, Constant value)
      Adds a static field.
      Parameters:
      field - non-null; the field to add
      value - null-ok; initial value for the field, if any
    • addInstanceField

      public void addInstanceField(EncodedField field)
      Adds an instance field.
      Parameters:
      field - non-null; the field to add
    • addDirectMethod

      public void addDirectMethod(EncodedMethod method)
      Adds a direct (static and/or private) method.
      Parameters:
      method - non-null; the method to add
    • addVirtualMethod

      public void addVirtualMethod(EncodedMethod method)
      Adds a virtual method.
      Parameters:
      method - non-null; the method to add
    • getMethods

      public ArrayList<EncodedMethod> getMethods()
      Gets all the methods in this class. The returned list is not linked in any way to the underlying lists contained in this instance, but the objects contained in the list are shared.
      Returns:
      non-null; list of all methods
    • debugPrint

      public void debugPrint(Writer out, boolean verbose)
      Prints out the contents of this instance, in a debugging-friendly way.
      Parameters:
      out - non-null; where to output to
      verbose - whether to be verbose with the output
    • addContents

      public void addContents(DexFile file)
      Populates a DexFile with items from within this instance. This will not add an item to the file for this instance itself (which should have been done by whatever refers to this instance).

      Note: Subclasses must override this to do something appropriate.

      Specified by:
      addContents in class Item
      Parameters:
      file - non-null; the file to populate
    • getStaticValuesConstant

      public CstArray getStaticValuesConstant()
      Gets a CstArray corresponding to staticValues if it contains any non-zero non-null values.
      Returns:
      null-ok; the corresponding constant or null if there are no values to encode
    • place0

      protected void place0(Section addedTo, int offset)
      Does additional work required when placing an instance. The default implementation of this method is a no-op. If a particular class needs to do something special, then it should override this method. In particular, if this instance did not know its write size up-front, then this method is responsible for setting it.
      Overrides:
      place0 in class OffsettedItem
      Parameters:
      addedTo - non-null; the section this instance has been added to
      offset - >= 0; the offset from the start of the section where this instance was placed
    • writeTo0

      public void writeTo0(DexFile file, AnnotatedOutput out)
      Performs the actual write of the contents of this instance to the given data section. This is called by OffsettedItem.writeTo(com.android.dx.dex.file.DexFile, com.android.dx.util.AnnotatedOutput), which will have taken care of ensuring alignment.
      Specified by:
      writeTo0 in class OffsettedItem
      Parameters:
      file - non-null; the file to use for reference
      out - non-null; where to write to