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

public final Class MixedItemSection

extends Section
Class Inheritance
Imports
org.droidparts.dexmaker.dx.util.AnnotatedOutput, .ExceptionWithContext, .Hex, java.util.*

A section of a .dex file which consists of a sequence of OffsettedItem objects, which may each be of a different concrete class and/or size

Note

It is invalid for an item in an instance of this class to have a larger alignment requirement than the alignment of this instance.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private final HashMap<OffsettedItem, OffsettedItem>
interns

non-null; items that have been explicitly interned

private final ArrayList<OffsettedItem>
items

non-null; the items in this part

private final MixedItemSection.SortType
sort

non-null; how to sort the items

private static final Comparator<OffsettedItem>
TYPE_SORTER

non-null; sorter which sorts instances by type

private int
writeSize

>= -1; the current size of this part, in bytes, or -1 if not yet calculated

Constructor Summary

AccessConstructor and Description
public
MixedItemSection(String
null-ok; the name of this instance, for annotation purposes
name
,
DexFile
non-null; file that this instance is part of
file
,
int
> 0; alignment requirement for the final output; must be a power of 2
alignment
,
MixedItemSection.SortType
how the items should be sorted in the final output
sort
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
public void
add(OffsettedItem
non-null; the item to add
item
)

Adds an item to this instance.

public <T extends OffsettedItem> T

Returns:

non-null; the equivalent already-interned instance
get
(T
non-null; the item to look for
item
)

Gets an item which was previously interned.

public int
getAbsoluteItemOffset(Item
non-null; the item in question
item
)

Implements abstract org.droidparts.dexmaker.dx.dex.file.Section.getAbsoluteItemOffset.

Returns the absolute file offset of the given item which must be contained in this section.
public <T extends OffsettedItem> T

Returns:

non-null; the equivalent interned instance
intern
(T
non-null; the item to intern
item
)

Interns an item in this instance, returning the interned instance (which may not be the one passed in).

public Collection<? extends Item>
items()

Implements abstract org.droidparts.dexmaker.dx.dex.file.Section.items.

Gets the collection of all the items in this section.
public void
placeItems()

Places all the items in this instance at particular offsets.

protected void
prepare0()

Implements abstract org.droidparts.dexmaker.dx.dex.file.Section.prepare0.

Does the main work of prepare.
public int

Returns:

>= 0; the size
size
()

Gets the size of this instance, in items.

public void
writeHeaderPart(AnnotatedOutput
non-null; where to write
out
)

Writes the portion of the file header that refers to this instance.

public void
writeIndexAnnotation(AnnotatedOutput
non-null; where to write to
out
,
ItemType
non-null; the item type of interest
itemType
,
String
non-null; the introductory string for non-empty indices
intro
)

Writes an index of contents of the items in this instance of the given type.

public int
writeSize()

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

Gets the size of this instance when output, in bytes.
protected void
writeTo0(AnnotatedOutput
non-null; where to write to
out
)

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

Writes this instance to the given raw data object.
Inherited from org.droidparts.dexmaker.dx.dex.file.Section:
aligngetAbsoluteOffsetgetAlignmentgetFilegetFileOffsetgetNamepreparesetFileOffsetthrowIfNotPreparedthrowIfPreparedvalidateAlignmentwriteTo

Field Detail

internsback to summary
private final HashMap<OffsettedItem, OffsettedItem> interns

non-null; items that have been explicitly interned

itemsback to summary
private final ArrayList<OffsettedItem> items

non-null; the items in this part

sortback to summary
private final MixedItemSection.SortType sort

non-null; how to sort the items

TYPE_SORTERback to summary
private static final Comparator<OffsettedItem> TYPE_SORTER

non-null; sorter which sorts instances by type

writeSizeback to summary
private int writeSize

>= -1; the current size of this part, in bytes, or -1 if not yet calculated

Constructor Detail

MixedItemSectionback to summary
public MixedItemSection(String name, DexFile file, int alignment, MixedItemSection.SortType sort)

Constructs an instance. The file offset is initially unknown.

Parameters
name:String

null-ok; the name of this instance, for annotation purposes

file:DexFile

non-null; file that this instance is part of

alignment:int

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

sort:MixedItemSection.SortType

how the items should be sorted in the final output

Method Detail

addback to summary
public void add(OffsettedItem item)

Adds an item to this instance. This will in turn tell the given item that it has been added to this instance. It is invalid to add the same item to more than one instance, nor to add the same items multiple times to a single instance.

Parameters
item:OffsettedItem

non-null; the item to add

getback to summary
public <T extends OffsettedItem> T get(T item)

Gets an item which was previously interned.

Parameters
item:T

non-null; the item to look for

Returns:T

non-null; the equivalent already-interned instance

getAbsoluteItemOffsetback to summary
public int getAbsoluteItemOffset(Item item)

Implements abstract org.droidparts.dexmaker.dx.dex.file.Section.getAbsoluteItemOffset.

Doc from org.droidparts.dexmaker.dx.dex.file.Section.getAbsoluteItemOffset.

Returns the absolute file offset of the given item which must be contained in this section. This is only valid to call once this instance has been assigned a file offset (via setFileOffset).

Note

Subclasses must implement this as appropriate for their contents.

Parameters
item:Item

non-null; the item in question

Returns:int

>= 0; the item's absolute file offset

Annotations
@Override
internback to summary
public <T extends OffsettedItem> T intern(T item)

Interns an item in this instance, returning the interned instance (which may not be the one passed in). This will add the item if no equal item has been added.

Parameters
item:T

non-null; the item to intern

Returns:T

non-null; the equivalent interned instance

itemsback to summary
public Collection<? extends Item> items()

Implements abstract org.droidparts.dexmaker.dx.dex.file.Section.items.

Doc from org.droidparts.dexmaker.dx.dex.file.Section.items.

Gets the collection of all the items in this section. It is not valid to attempt to change the returned list.

Returns:Collection<? extends Item>

non-null; the items

Annotations
@Override
placeItemsback to summary
public void placeItems()

Places all the items in this instance at particular offsets. This will call OffsettedItem#place on each item. If an item does not know its write size before the call to place, it is that call which is responsible for setting the write size. This method may only be called once per instance; subsequent calls will throw an exception.

prepare0back to summary
protected void prepare0()

Implements abstract org.droidparts.dexmaker.dx.dex.file.Section.prepare0.

Doc from org.droidparts.dexmaker.dx.dex.file.Section.prepare0.

Does the main work of prepare.

Annotations
@Override
sizeback to summary
public int size()

Gets the size of this instance, in items.

Returns:int

>= 0; the size

writeHeaderPartback to summary
public void writeHeaderPart(AnnotatedOutput out)

Writes the portion of the file header that refers to this instance.

Parameters
out:AnnotatedOutput

non-null; where to write

writeIndexAnnotationback to summary
public void writeIndexAnnotation(AnnotatedOutput out, ItemType itemType, String intro)

Writes an index of contents of the items in this instance of the given type. If there are none, this writes nothing. If there are any, then the index is preceded by the given intro string.

Parameters
out:AnnotatedOutput

non-null; where to write to

itemType:ItemType

non-null; the item type of interest

intro:String

non-null; the introductory string for non-empty indices

writeSizeback to summary
public int writeSize()

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

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

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

Returns:int

>= 0; the size of this instance, in bytes

Annotations
@Override
writeTo0back to summary
protected void writeTo0(AnnotatedOutput out)

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

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

Writes this instance to the given raw data object. This gets called by writeTo after aligning the cursor of out and verifying that either the assigned file offset matches the actual cursor out or that the file offset was not previously assigned, in which case it gets assigned to out's cursor.

Parameters
out:AnnotatedOutput

non-null; where to write to

Annotations
@Override
org.droidparts.dexmaker.dx.dex.file back to summary

pack-priv final Enum MixedItemSection.SortType

extends Enum<MixedItemSection.SortType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final MixedItemSection.SortType
INSTANCE

sort in class-major order, with instances sorted per-class

public static final MixedItemSection.SortType
NONE

no sorting

public static final MixedItemSection.SortType
TYPE

sort by type only

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static MixedItemSection.SortType
public static MixedItemSection.SortType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INSTANCEback to summary
public static final MixedItemSection.SortType INSTANCE

sort in class-major order, with instances sorted per-class

NONEback to summary
public static final MixedItemSection.SortType NONE

no sorting

TYPEback to summary
public static final MixedItemSection.SortType TYPE

sort by type only

Constructor Detail

SortTypeback to summary
private SortType()

Method Detail

valueOfback to summary
public static MixedItemSection.SortType valueOf(String name)
valuesback to summary
public static MixedItemSection.SortType[] values()