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

public final Class AnnotationItem

extends OffsettedItem
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.annotation.Annotation, .AnnotationVisibility, .NameValuePair, org.droidparts.dexmaker.dx.rop.cst.Constant, .CstString, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .ByteArrayAnnotatedOutput, java.util.Arrays, .Comparator

Single annotation, which consists of a type and a set of name-value element pairs.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AnnotationItem.TypeIdSorter

Comparator that sorts (outer) instances by type id index.

Field Summary

Modifier and TypeField and Description
private static final int
ALIGNMENT

the required alignment for instances of this class

private final Annotation
annotation

non-null; the annotation to represent

private byte[]
encodedForm

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

private TypeIdItem
type

null-ok; type reference for the annotation type; set during addContents

private static final AnnotationItem.TypeIdSorter
TYPE_ID_SORTER

non-null; unique instance of TypeIdSorter

private static final int
VISIBILITY_BUILD

annotation visibility constant: visible at build time only

private static final int
VISIBILITY_RUNTIME

annotation visibility constant: visible at runtime

private static final int
VISIBILITY_SYSTEM

annotation visibility constant: visible at runtime only to system

Constructor Summary

AccessConstructor and Description
public
AnnotationItem(Annotation
non-null; annotation to represent
annotation
)

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
annotateTo(AnnotatedOutput
non-null; where to output to
out
,
String
non-null; prefix for each line of output
prefix
)

Write a (listing file) annotation for this instance to the given output, that consumes no bytes of output.

protected int
compareTo0(OffsettedItem
non-null; instance to compare to
other
)

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

Compares this instance to another which is guaranteed to be of the same class.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public ItemType
itemType()

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

Returns the item type for this instance.
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 static void
sortByTypeIdIndex(AnnotationItem[]
non-null; array to sort
array
)

Sorts an array of instances, in place, by type id index, ignoring all other aspects of the elements.

public String
toHuman()

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

Gets a short human-readable string representing this instance.
protected 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:
compareToequalsgetAbsoluteOffsetgetAbsoluteOffsetOr0getAlignmentgetRelativeOffsetoffsetStringplacesetWriteSizewriteSizewriteTo

Field Detail

ALIGNMENTback to summary
private static final int ALIGNMENT

the required alignment for instances of this class

annotationback to summary
private final Annotation annotation

non-null; the annotation to represent

encodedFormback to summary
private byte[] encodedForm

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

typeback to summary
private TypeIdItem type

null-ok; type reference for the annotation type; set during addContents

TYPE_ID_SORTERback to summary
private static final AnnotationItem.TypeIdSorter TYPE_ID_SORTER

non-null; unique instance of TypeIdSorter

VISIBILITY_BUILDback to summary
private static final int VISIBILITY_BUILD

annotation visibility constant: visible at build time only

VISIBILITY_RUNTIMEback to summary
private static final int VISIBILITY_RUNTIME

annotation visibility constant: visible at runtime

VISIBILITY_SYSTEMback to summary
private static final int VISIBILITY_SYSTEM

annotation visibility constant: visible at runtime only to system

Constructor Detail

AnnotationItemback to summary
public AnnotationItem(Annotation annotation)

Constructs an instance.

Parameters
annotation:Annotation

non-null; annotation to represent

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

annotateToback to summary
public void annotateTo(AnnotatedOutput out, String prefix)

Write a (listing file) annotation for this instance to the given output, that consumes no bytes of output. This is for annotating a reference to this instance at the point of the reference.

Parameters
out:AnnotatedOutput

non-null; where to output to

prefix:String

non-null; prefix for each line of output

compareTo0back to summary
protected int compareTo0(OffsettedItem other)

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

Doc from org.droidparts.dexmaker.dx.dex.file.OffsettedItem.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:OffsettedItem

non-null; instance to compare to

Returns:int

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

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
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
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
sortByTypeIdIndexback to summary
public static void sortByTypeIdIndex(AnnotationItem[] array)

Sorts an array of instances, in place, by type id index, ignoring all other aspects of the elements. This is only valid to use after type id indices are known.

Parameters
array:AnnotationItem[]

non-null; array to sort

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
protected 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
org.droidparts.dexmaker.dx.dex.file back to summary

private Class AnnotationItem.TypeIdSorter

extends Object
implements Comparator<AnnotationItem>
Class Inheritance
  • java.lang.Object
  • org.droidparts.dexmaker.dx.dex.file.AnnotationItem.TypeIdSorter
All Implemented Interfaces
java.util.Comparator

Comparator that sorts (outer) instances by type id index.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(AnnotationItem
the first object to be compared.
item1
,
AnnotationItem
the second object to be compared.
item2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TypeIdSorterback to summary
private TypeIdSorter()

Method Detail

compareback to summary
public int compare(AnnotationItem item1, AnnotationItem item2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

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

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

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
item1:AnnotationItem

the first object to be compared.

item2:AnnotationItem

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.