Class ClassDefItem


public final class ClassDefItem extends IndexedItem
Representation of a Dalvik class, which is basically a set of members (fields or methods) along with a few more pieces of information.
  • Constructor Details

    • ClassDefItem

      public ClassDefItem(CstType thisClass, int accessFlags, CstType superclass, TypeList interfaces, CstString sourceFile)
      Constructs an instance. Its sets of members and annotations are initially empty.
      Parameters:
      thisClass - non-null; type constant for this class
      accessFlags - access flags
      superclass - null-ok; superclass or null if this class is a/the root class
      interfaces - non-null; list of implemented interfaces
      sourceFile - null-ok; source file name or null if unknown
  • 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
    • writeSize

      public int writeSize()
      Gets the size of this instance when written, in bytes.
      Specified by:
      writeSize in class Item
      Returns:
      >= 0; the write size
    • 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
    • writeTo

      public void writeTo(DexFile file, AnnotatedOutput out)
      Writes the representation of this instance to the given data section, using the given DexFile to look things up as needed. If this instance keeps track of its offset, then this method will note the written offset and will also throw an exception if this instance has already been written.
      Specified by:
      writeTo in class Item
      Parameters:
      file - non-null; the file to use for reference
      out - non-null; where to write to
    • getThisClass

      public CstType getThisClass()
      Gets the constant corresponding to this class.
      Returns:
      non-null; the constant
    • getAccessFlags

      public int getAccessFlags()
      Gets the access flags.
      Returns:
      the access flags
    • getSuperclass

      public CstType getSuperclass()
      Gets the superclass.
      Returns:
      null-ok; the superclass or null if this class is a/the root class
    • getInterfaces

      public TypeList getInterfaces()
      Gets the list of interfaces implemented.
      Returns:
      non-null; the interfaces list
    • getSourceFile

      public CstString getSourceFile()
      Gets the source file name.
      Returns:
      null-ok; the source file name or null if unknown
    • 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
    • setClassAnnotations

      public void setClassAnnotations(Annotations annotations, DexFile dexFile)
      Sets the direct annotations on this class. These are annotations made on the class, per se, as opposed to on one of its members. It is only valid to call this method at most once per instance.
      Parameters:
      annotations - non-null; annotations to set for this class
      dexFile - non-null; dex output
    • addFieldAnnotations

      public void addFieldAnnotations(CstFieldRef field, Annotations annotations, DexFile dexFile)
      Adds a field annotations item to this class.
      Parameters:
      field - non-null; field in question
      annotations - non-null; associated annotations to add
      dexFile - non-null; dex output
    • addMethodAnnotations

      public void addMethodAnnotations(CstMethodRef method, Annotations annotations, DexFile dexFile)
      Adds a method annotations item to this class.
      Parameters:
      method - non-null; method in question
      annotations - non-null; associated annotations to add
      dexFile - non-null; dex output
    • addParameterAnnotations

      public void addParameterAnnotations(CstMethodRef method, AnnotationsList list, DexFile dexFile)
      Adds a parameter annotations item to this class.
      Parameters:
      method - non-null; method in question
      list - non-null; associated list of annotation sets to add
      dexFile - non-null; dex output
    • getMethodAnnotations

      public Annotations getMethodAnnotations(CstMethodRef method)
      Gets the method annotations for a given method, if any. This is meant for use by debugging / dumping code.
      Parameters:
      method - non-null; the method
      Returns:
      null-ok; the method annotations, if any
    • getParameterAnnotations

      public AnnotationsList getParameterAnnotations(CstMethodRef method)
      Gets the parameter annotations for a given method, if any. This is meant for use by debugging / dumping code.
      Parameters:
      method - non-null; the method
      Returns:
      null-ok; the parameter annotations, if any
    • 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