Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.file

public final Class ClassDataItem

extends OffsettedItem
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.cst.*, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .ByteArrayAnnotatedOutput, .Writers, java.io.PrintWriter, .Writer, java.util.ArrayList, .Collections, .HashMap

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.

Field Summary

Modifier and TypeField and Description
private final ArrayList<EncodedMethod>
directMethods

non-null; list of direct methods

private byte[]
encodedForm

null-ok; encoded form, ready for writing to a file; set during place0

private final ArrayList<EncodedField>
instanceFields

non-null; list of instance fields

private final ArrayList<EncodedField>
staticFields

non-null; list of static fields

private final HashMap<EncodedField, Constant>
staticValues

non-null; list of initial values for static fields

private CstArray
staticValuesConstant

null-ok; static initializer list; set in addContents

private final CstType
thisClass

non-null; what class this data is for, just for listing generation

private final ArrayList<EncodedMethod>
virtualMethods

non-null; list of virtual methods

Constructor Summary

AccessConstructor and Description
public
ClassDataItem(CstType
non-null; what class this data is for, just for listing generation
thisClass
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
public void
addContents(DexFile
non-null; the file to populate
file
)

Implements abstract org.droidparts.dexmaker.dx.dex.file.Item.addContents.

Populates a DexFile with items from within this instance.
public void
addDirectMethod(EncodedMethod
non-null; the method to add
method
)

Adds a direct (static and/or private) method.

public void
addInstanceField(EncodedField
non-null; the field to add
field
)

Adds an instance field.

public void
addStaticField(EncodedField
non-null; the field to add
field
,
Constant
null-ok; initial value for the field, if any
value
)

Adds a static field.

public void
addVirtualMethod(EncodedMethod
non-null; the method to add
method
)

Adds a virtual method.

public void
debugPrint(Writer
non-null; where to output to
out
,
boolean
whether to be verbose with the output
verbose
)

Prints out the contents of this instance, in a debugging-friendly way.

private static void
encodeList(DexFile
non-null; file this instance is part of
file
,
AnnotatedOutput
non-null; where to write to
out
,
String
non-null; the label for the purposes of annotation
label
,
ArrayList<? extends EncodedMember>
non-null; the list in question
list
)

Helper for encodeOutput, which writes out the given list.

private void
encodeOutput(DexFile
non-null; file this instance is part of
file
,
AnnotatedOutput
non-null; where to write to
out
)

Writes out the encoded form of this instance.

private static void
encodeSize(DexFile
non-null; file this instance is part of
file
,
AnnotatedOutput
non-null; where to write to
out
,
String
non-null; the label for the purposes of annotation
label
,
int
>= 0; the size to write
size
)

Helper for encodeOutput, which writes out the given size value, annotating it as well (if annotations are enabled).

public ArrayList<EncodedMethod>

Returns:

non-null; list of all methods
getMethods
()

Gets all the methods in this class.

public CstArray

Returns:

null-ok; the corresponding constant or null if there are no values to encode
getStaticValuesConstant
()

Gets a CstArray corresponding to staticValues if it contains any non-zero non-null values.

public boolean

Returns:

true if this instance is empty or false if at least one element has been added to it
isEmpty
()

Returns whether this instance is empty.

public ItemType
itemType()

Implements abstract org.droidparts.dexmaker.dx.dex.file.Item.itemType.

Returns the item type for this instance.
private CstArray

Returns:

null-ok; the corresponding constant or null if there are no values to encode
makeStaticValuesConstant
()

Gets a CstArray corresponding to staticValues if it contains any non-zero non-null values.

protected void
place0(Section
non-null; the section this instance has been added to
addedTo
,
int
>= 0; the offset from the start of the section where this instance was placed
offset
)

Overrides org.droidparts.dexmaker.dx.dex.file.OffsettedItem.place0.

Does additional work required when placing an instance.
public String
toHuman()

Implements abstract org.droidparts.dexmaker.dx.dex.file.OffsettedItem.toHuman.

Gets a short human-readable string representing this instance.
public void
writeTo0(DexFile
non-null; the file to use for reference
file
,
AnnotatedOutput
non-null; where to write to
out
)

Implements abstract org.droidparts.dexmaker.dx.dex.file.OffsettedItem.writeTo0.

Performs the actual write of the contents of this instance to the given data section.
Inherited from org.droidparts.dexmaker.dx.dex.file.OffsettedItem:
compareTocompareTo0equalsgetAbsoluteOffsetgetAbsoluteOffsetOr0getAlignmentgetRelativeOffsetoffsetStringplacesetWriteSizewriteSizewriteTo

Field Detail

directMethodsback to summary
private final ArrayList<EncodedMethod> directMethods

non-null; list of direct methods

encodedFormback to summary
private byte[] encodedForm

null-ok; encoded form, ready for writing to a file; set during place0

instanceFieldsback to summary
private final ArrayList<EncodedField> instanceFields

non-null; list of instance fields

staticFieldsback to summary
private final ArrayList<EncodedField> staticFields

non-null; list of static fields

staticValuesback to summary
private final HashMap<EncodedField, Constant> staticValues

non-null; list of initial values for static fields

staticValuesConstantback to summary
private CstArray staticValuesConstant

null-ok; static initializer list; set in addContents

thisClassback to summary
private final CstType thisClass

non-null; what class this data is for, just for listing generation

virtualMethodsback to summary
private final ArrayList<EncodedMethod> virtualMethods

non-null; list of virtual methods

Constructor Detail

ClassDataItemback to summary
public ClassDataItem(CstType thisClass)

Constructs an instance. Its sets of members are initially empty.

Parameters
thisClass:CstType

non-null; what class this data is for, just for listing generation

Method Detail

addContentsback to summary
public void addContents(DexFile file)

Implements abstract org.droidparts.dexmaker.dx.dex.file.Item.addContents.

Doc from org.droidparts.dexmaker.dx.dex.file.Item.addContents.

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.

Parameters
file:DexFile

non-null; the file to populate

Annotations
@Override
addDirectMethodback to summary
public void addDirectMethod(EncodedMethod method)

Adds a direct (static and/or private) method.

Parameters
method:EncodedMethod

non-null; the method to add

addInstanceFieldback to summary
public void addInstanceField(EncodedField field)

Adds an instance field.

Parameters
field:EncodedField

non-null; the field to add

addStaticFieldback to summary
public void addStaticField(EncodedField field, Constant value)

Adds a static field.

Parameters
field:EncodedField

non-null; the field to add

value:Constant

null-ok; initial value for the field, if any

addVirtualMethodback to summary
public void addVirtualMethod(EncodedMethod method)

Adds a virtual method.

Parameters
method:EncodedMethod

non-null; the method to add

debugPrintback to summary
public void debugPrint(Writer out, boolean verbose)

Prints out the contents of this instance, in a debugging-friendly way.

Parameters
out:Writer

non-null; where to output to

verbose:boolean

whether to be verbose with the output

encodeListback to summary
private static void encodeList(DexFile file, AnnotatedOutput out, String label, ArrayList<? extends EncodedMember> list)

Helper for encodeOutput, which writes out the given list. It also annotates the items (if any and if annotations are enabled).

Parameters
file:DexFile

non-null; file this instance is part of

out:AnnotatedOutput

non-null; where to write to

label:String

non-null; the label for the purposes of annotation

list:ArrayList<? extends EncodedMember>

non-null; the list in question

encodeOutputback to summary
private void encodeOutput(DexFile file, AnnotatedOutput out)

Writes out the encoded form of this instance.

Parameters
file:DexFile

non-null; file this instance is part of

out:AnnotatedOutput

non-null; where to write to

encodeSizeback to summary
private static void encodeSize(DexFile file, AnnotatedOutput out, String label, int size)

Helper for encodeOutput, which writes out the given size value, annotating it as well (if annotations are enabled).

Parameters
file:DexFile

non-null; file this instance is part of

out:AnnotatedOutput

non-null; where to write to

label:String

non-null; the label for the purposes of annotation

size:int

>= 0; the size to write

getMethodsback to summary
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:ArrayList<EncodedMethod>

non-null; list of all methods

getStaticValuesConstantback to summary
public CstArray getStaticValuesConstant()

Gets a CstArray corresponding to staticValues if it contains any non-zero non-null values.

Returns:CstArray

null-ok; the corresponding constant or null if there are no values to encode

isEmptyback to summary
public boolean isEmpty()

Returns whether this instance is empty.

Returns:boolean

true if this instance is empty or false if at least one element has been added to it

itemTypeback to summary
public ItemType itemType()

Implements abstract org.droidparts.dexmaker.dx.dex.file.Item.itemType.

Doc from org.droidparts.dexmaker.dx.dex.file.Item.itemType.

Returns the item type for this instance.

Returns:ItemType

non-null; the item type

Annotations
@Override
makeStaticValuesConstantback to summary
private CstArray makeStaticValuesConstant()

Gets a CstArray corresponding to staticValues if it contains any non-zero non-null values.

Returns:CstArray

null-ok; the corresponding constant or null if there are no values to encode

place0back to summary
protected void place0(Section addedTo, int offset)

Overrides org.droidparts.dexmaker.dx.dex.file.OffsettedItem.place0.

Doc from org.droidparts.dexmaker.dx.dex.file.OffsettedItem.place0.

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.

Parameters
addedTo:Section

non-null; the section this instance has been added to

offset:int

>= 0; the offset from the start of the section where this instance was placed

Annotations
@Override
toHumanback to summary
public String toHuman()

Implements abstract org.droidparts.dexmaker.dx.dex.file.OffsettedItem.toHuman.

Doc from org.droidparts.dexmaker.dx.dex.file.OffsettedItem.toHuman.

Gets a short human-readable string representing this instance.

Returns:String

non-null; the human form

Annotations
@Override
writeTo0back to summary
public void writeTo0(DexFile file, AnnotatedOutput out)

Implements abstract org.droidparts.dexmaker.dx.dex.file.OffsettedItem.writeTo0.

Doc from org.droidparts.dexmaker.dx.dex.file.OffsettedItem.writeTo0.

Performs the actual write of the contents of this instance to the given data section. This is called by writeTo, which will have taken care of ensuring alignment.

Parameters
file:DexFile

non-null; the file to use for reference

out:AnnotatedOutput

non-null; where to write to

Annotations
@Override