Package com.android.dx.dex.file
Class OffsettedItem
java.lang.Object
com.android.dx.dex.file.Item
com.android.dx.dex.file.OffsettedItem
- All Implemented Interfaces:
Comparable<OffsettedItem>
- Direct Known Subclasses:
AnnotationItem
,AnnotationsDirectoryItem
,AnnotationSetItem
,AnnotationSetRefItem
,CallSiteItem
,ClassDataItem
,CodeItem
,DebugInfoItem
,EncodedArrayItem
,MapItem
,StringDataItem
,TypeListItem
,UniformListItem
An item in a Dalvik file which is referenced by absolute offset.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
compareTo
(OffsettedItem other) Comparisons for this class are defined to be class-major (if the classes don't match then the objects are not equal), withcompareTo0(com.android.dx.dex.file.OffsettedItem)
deciding same-class comparisons.protected int
compareTo0
(OffsettedItem other) Compares this instance to another which is guaranteed to be of the same class.final boolean
Comparisons for this class are defined to be type-major (if the types don't match then the objects are not equal), withcompareTo0(com.android.dx.dex.file.OffsettedItem)
deciding same-type comparisons.final int
Gets the absolute item offset.static int
Gets the absolute offset of the given item, returning0
if handednull
.final int
Gets the alignment requirement of this instance.final int
Gets the relative item offset.final String
Gets the absolute offset of this item as a string, suitable for including in annotations.final int
Indicates that this item has been added to the given section at the given offset.protected void
Does additional work required when placing an instance.final void
setWriteSize
(int writeSize) Sets the write size of this item.abstract String
toHuman()
Gets a short human-readable string representing this instance.final int
Gets the size of this instance when written, in bytes.final void
writeTo
(DexFile file, AnnotatedOutput out) Writes the representation of this instance to the given data section, using the givenDexFile
to look things up as needed.protected abstract void
writeTo0
(DexFile file, AnnotatedOutput out) Performs the actual write of the contents of this instance to the given data section.Methods inherited from class com.android.dx.dex.file.Item
addContents, itemType, typeName
-
Constructor Details
-
OffsettedItem
public OffsettedItem(int alignment, int writeSize) Constructs an instance. The offset is initially unassigned.- Parameters:
alignment
-> 0;
output alignment requirement; must be a power of 2writeSize
->= -1;
the size of this instance when written, in bytes, or-1
if not immediately known
-
-
Method Details
-
getAbsoluteOffsetOr0
Gets the absolute offset of the given item, returning0
if handednull
.- Parameters:
item
-null-ok;
the item in question- Returns:
>= 0;
the item's absolute offset, or0
ifitem == null
-
equals
Comparisons for this class are defined to be type-major (if the types don't match then the objects are not equal), withcompareTo0(com.android.dx.dex.file.OffsettedItem)
deciding same-type comparisons. -
compareTo
Comparisons for this class are defined to be class-major (if the classes don't match then the objects are not equal), withcompareTo0(com.android.dx.dex.file.OffsettedItem)
deciding same-class comparisons.- Specified by:
compareTo
in interfaceComparable<OffsettedItem>
-
setWriteSize
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
-> 0;
the write size, in bytes
-
writeSize
public final int writeSize()Gets the size of this instance when written, in bytes.- Specified by:
writeSize
in classItem
- Returns:
>= 0;
the write size- Throws:
UnsupportedOperationException
- thrown if the write size is not yet known
-
writeTo
Writes the representation of this instance to the given data section, using the givenDexFile
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. -
getRelativeOffset
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:
>= 0;
the offset- Throws:
RuntimeException
- thrown if the offset is not yet known
-
getAbsoluteOffset
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:
>= 0;
the offset- Throws:
RuntimeException
- thrown if the offset is not yet known
-
place
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
-non-null;
the section this instance has been added tooffset
->= 0;
the desired offset from the start of the section where this instance was placed- Returns:
>= 0;
the offset that this instance should be placed at in order to meet its alignment constraint
-
getAlignment
public final int getAlignment()Gets the alignment requirement of this instance. An instance should only be written when so aligned.- Returns:
> 0;
the alignment requirement; must be a power of 2
-
offsetString
Gets the absolute offset of this item as a string, suitable for including in annotations.- Returns:
non-null;
the offset string
-
toHuman
Gets a short human-readable string representing this instance.- Returns:
non-null;
the human form
-
compareTo0
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
-non-null;
instance to compare to- Returns:
-1
,0
, or1
, depending on the sort order of this instance and the other
-
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
-non-null;
the section this instance has been added tooffset
->= 0;
the offset from the start of the section where this instance was placed
-
writeTo0
Performs the actual write of the contents of this instance to the given data section. This is called bywriteTo(com.android.dx.dex.file.DexFile, com.android.dx.util.AnnotatedOutput)
, which will have taken care of ensuring alignment.- Parameters:
file
-non-null;
the file to use for referenceout
-non-null;
where to write to
-