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

public abstract Class OffsettedItem

extends Item
implements Comparable<OffsettedItem>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
org.droidparts.dexmaker.dx.dex.file.StringDataItem, org.droidparts.dexmaker.dx.dex.file.TypeListItem, org.droidparts.dexmaker.dx.dex.file.UniformListItem, org.droidparts.dexmaker.dx.dex.file.AnnotationItem, org.droidparts.dexmaker.dx.dex.file.AnnotationsDirectoryItem, org.droidparts.dexmaker.dx.dex.file.AnnotationSetItem, org.droidparts.dexmaker.dx.dex.file.AnnotationSetRefItem, org.droidparts.dexmaker.dx.dex.file.ClassDataItem, org.droidparts.dexmaker.dx.dex.file.CodeItem, org.droidparts.dexmaker.dx.dex.file.DebugInfoItem, org.droidparts.dexmaker.dx.dex.file.EncodedArrayItem, org.droidparts.dexmaker.dx.dex.file.MapItem
Imports
org.droidparts.dexmaker.dx.util.AnnotatedOutput, .ExceptionWithContext

An item in a Dalvik file which is referenced by absolute offset.

Field Summary

Modifier and TypeField and Description
private Section
addedTo

null-ok; section the item was added to, or null if not yet added

private final int
alignment

> 0; alignment requirement

private int
offset

>= -1; assigned offset of the item from the start of its section, or -1 if not yet assigned

private int
writeSize

>= -1; the size of this instance when written, in bytes, or -1 if not yet known

Constructor Summary

AccessConstructor and Description
public
OffsettedItem(int
> 0; output alignment requirement; must be a power of 2
alignment
,
int
>= -1; the size of this instance when written, in bytes, or -1 if not immediately known
writeSize
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
public final int
compareTo(OffsettedItem
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
protected int

Returns:

-1, 0, or 1, depending on the sort order of this instance and the other
compareTo0
(OffsettedItem
non-null; instance to compare to
other
)

Compares this instance to another which is guaranteed to be of the same class.

public final boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public final int

Returns:

>= 0; the offset
getAbsoluteOffset
()

Gets the absolute item offset.

public static int

Returns:

>= 0; the item's absolute offset, or 0 if item == null
getAbsoluteOffsetOr0
(OffsettedItem
null-ok; the item in question
item
)

Gets the absolute offset of the given item, returning 0 if handed null.

public final int

Returns:

> 0; the alignment requirement; must be a power of 2
getAlignment
()

Gets the alignment requirement of this instance.

public final int

Returns:

>= 0; the offset
getRelativeOffset
()

Gets the relative item offset.

public final String

Returns:

non-null; the offset string
offsetString
()

Gets the absolute offset of this item as a string, suitable for including in annotations.

public final int

Returns:

>= 0; the offset that this instance should be placed at in order to meet its alignment constraint
place
(Section
non-null; the section this instance has been added to
addedTo
,
int
>= 0; the desired offset from the start of the section where this instance was placed
offset
)

Indicates that this item has been added to the given section at the given offset.

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
)

Does additional work required when placing an instance.

public final void
setWriteSize(int
> 0; the write size, in bytes
writeSize
)

Sets the write size of this item.

public abstract String

Returns:

non-null; the human form
toHuman
()

Gets a short human-readable string representing this instance.

public final int
writeSize()

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

Gets the size of this instance when written, in bytes.
public final void
writeTo(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.Item.writeTo.

Writes the representation of this instance to the given data section, using the given DexFile to look things up as needed.
protected abstract void
writeTo0(DexFile
non-null; the file to use for reference
file
,
AnnotatedOutput
non-null; where to write to
out
)

Performs the actual write of the contents of this instance to the given data section.

Inherited from org.droidparts.dexmaker.dx.dex.file.Item:
addContentsitemTypetypeName

Field Detail

addedToback to summary
private Section addedTo

null-ok; section the item was added to, or null if not yet added

alignmentback to summary
private final int alignment

> 0; alignment requirement

offsetback to summary
private int offset

>= -1; assigned offset of the item from the start of its section, or -1 if not yet assigned

writeSizeback to summary
private int writeSize

>= -1; the size of this instance when written, in bytes, or -1 if not yet known

Constructor Detail

OffsettedItemback to summary
public OffsettedItem(int alignment, int writeSize)

Constructs an instance. The offset is initially unassigned.

Parameters
alignment:int

> 0; output alignment requirement; must be a power of 2

writeSize:int

>= -1; the size of this instance when written, in bytes, or -1 if not immediately known

Method Detail

compareToback to summary
public final int compareTo(OffsettedItem other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z. Comparisons for this class are defined to be class-major (if the classes don't match then the objects are not equal), with compareTo0 deciding same-class comparisons.

Parameters
other:OffsettedItem

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

compareTo0back to summary
protected int compareTo0(OffsettedItem other)

Compares this instance to another which is guaranteed to be of the same class. The default implementation of this method is to throw an exception (unsupported operation). If a particular class needs to actually sort, then it should override this method.

Parameters
other:OffsettedItem

non-null; instance to compare to

Returns:int

-1, 0, or 1, depending on the sort order of this instance and the other

equalsback to summary
public final boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. Comparisons for this class are defined to be type-major (if the types don't match then the objects are not equal), with compareTo0 deciding same-type comparisons.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAbsoluteOffsetback to summary
public final int getAbsoluteOffset()

Gets the absolute item offset. The offset is from the start of the file which the instance was written to.

Returns:int

>= 0; the offset

Exceptions
RuntimeException:
thrown if the offset is not yet known
getAbsoluteOffsetOr0back to summary
public static int getAbsoluteOffsetOr0(OffsettedItem item)

Gets the absolute offset of the given item, returning 0 if handed null.

Parameters
item:OffsettedItem

null-ok; the item in question

Returns:int

>= 0; the item's absolute offset, or 0 if item == null

getAlignmentback to summary
public final int getAlignment()

Gets the alignment requirement of this instance. An instance should only be written when so aligned.

Returns:int

> 0; the alignment requirement; must be a power of 2

getRelativeOffsetback to summary
public final int getRelativeOffset()

Gets the relative item offset. The offset is from the start of the section which the instance was written to.

Returns:int

>= 0; the offset

Exceptions
RuntimeException:
thrown if the offset is not yet known
offsetStringback to summary
public final String offsetString()

Gets the absolute offset of this item as a string, suitable for including in annotations.

Returns:String

non-null; the offset string

placeback to summary
public final int place(Section addedTo, int offset)

Indicates that this item has been added to the given section at the given offset. It is only valid to call this method once per instance.

Parameters
addedTo:Section

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

offset:int

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

Returns:int

>= 0; the offset that this instance should be placed at in order to meet its alignment constraint

place0back to summary
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.

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

setWriteSizeback to summary
public final void setWriteSize(int writeSize)

Sets the write size of this item. This may only be called once per instance, and only if the size was unknown upon instance creation.

Parameters
writeSize:int

> 0; the write size, in bytes

toHumanback to summary
public abstract String toHuman()

Gets a short human-readable string representing this instance.

Returns:String

non-null; the human form

writeSizeback to summary
public final int writeSize()

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

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

Gets the size of this instance when written, in bytes.

Returns:int

>= 0; the write size

Annotations
@Override
Exceptions
UnsupportedOperationException:
thrown if the write size is not yet known
writeToback to summary
public final void writeTo(DexFile file, AnnotatedOutput out)

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

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

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.

Parameters
file:DexFile

non-null; the file to use for reference

out:AnnotatedOutput

non-null; where to write to

Annotations
@Override
writeTo0back to summary
protected abstract 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 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