AnnotationItempublic final class AnnotationItem extends OffsettedItem Single annotation, which consists of a type and a set of name-value
element pairs. |
Fields Summary |
---|
private static final int | VISIBILITY_BUILDannotation visibility constant: visible at build time only | private static final int | VISIBILITY_RUNTIMEannotation visibility constant: visible at runtime | private static final int | VISIBILITY_SYSTEMannotation visibility constant: visible at runtime only to system | private static final int | ALIGNMENTthe required alignment for instances of this class | private static final TypeIdSorter | TYPE_ID_SORTER{@code non-null;} unique instance of {@link #TypeIdSorter} | private final com.android.dx.rop.annotation.Annotation | annotation{@code non-null;} the annotation to represent | private TypeIdItem | type{@code null-ok;} type reference for the annotation type; set during
{@link #addContents} | private byte[] | encodedForm{@code null-ok;} encoded form, ready for writing to a file; set during
{@link #place0} |
Constructors Summary |
---|
public AnnotationItem(com.android.dx.rop.annotation.Annotation annotation, DexFile dexFile)Constructs an instance.
/*
* The write size isn't known up-front because (the variable-lengthed)
* leb128 type is used to represent some things.
*/
super(ALIGNMENT, -1);
if (annotation == null) {
throw new NullPointerException("annotation == null");
}
this.annotation = annotation;
this.type = null;
this.encodedForm = null;
addContents(dexFile);
|
Methods Summary |
---|
public void | addContents(DexFile file){@inheritDoc}
type = file.getTypeIds().intern(annotation.getType());
ValueEncoder.addContents(file, annotation);
| public void | annotateTo(com.android.dx.util.AnnotatedOutput out, java.lang.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.
out.annotate(0, prefix + "visibility: " +
annotation.getVisibility().toHuman());
out.annotate(0, prefix + "type: " + annotation.getType().toHuman());
for (NameValuePair pair : annotation.getNameValuePairs()) {
CstString name = pair.getName();
Constant value = pair.getValue();
out.annotate(0, prefix + name.toHuman() + ": " +
ValueEncoder.constantToHuman(value));
}
| protected int | compareTo0(OffsettedItem other){@inheritDoc}
AnnotationItem otherAnnotation = (AnnotationItem) other;
return annotation.compareTo(otherAnnotation.annotation);
| public int | hashCode(){@inheritDoc}
return annotation.hashCode();
| public ItemType | itemType(){@inheritDoc}
return ItemType.TYPE_ANNOTATION_ITEM;
| protected void | place0(Section addedTo, int offset){@inheritDoc}
// Encode the data and note the size.
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
ValueEncoder encoder = new ValueEncoder(addedTo.getFile(), out);
encoder.writeAnnotation(annotation, false);
encodedForm = out.toByteArray();
// Add one for the visibility byte in front of the encoded annotation.
setWriteSize(encodedForm.length + 1);
| public static void | sortByTypeIdIndex(com.android.dx.dex.file.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.
Arrays.sort(array, TYPE_ID_SORTER);
| public java.lang.String | toHuman(){@inheritDoc}
return annotation.toHuman();
| protected void | writeTo0(DexFile file, com.android.dx.util.AnnotatedOutput out){@inheritDoc}
boolean annotates = out.annotates();
AnnotationVisibility visibility = annotation.getVisibility();
if (annotates) {
out.annotate(0, offsetString() + " annotation");
out.annotate(1, " visibility: VISBILITY_" + visibility);
}
switch (visibility) {
case BUILD: out.writeByte(VISIBILITY_BUILD); break;
case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
case SYSTEM: out.writeByte(VISIBILITY_SYSTEM); break;
default: {
// EMBEDDED shouldn't appear at the top level.
throw new RuntimeException("shouldn't happen");
}
}
if (annotates) {
/*
* The output is to be annotated, so redo the work previously
* done by place0(), except this time annotations will actually
* get emitted.
*/
ValueEncoder encoder = new ValueEncoder(file, out);
encoder.writeAnnotation(annotation, true);
} else {
out.write(encodedForm);
}
|
|