FileDocCategorySizeDatePackage
AnnotationSetItem.javaAPI DocAndroid 5.1 API4636Thu Mar 12 22:18:30 GMT 2015com.android.dx.dex.file

AnnotationSetItem

public final class AnnotationSetItem extends OffsettedItem
Set of annotations, where no annotation type appears more than once.

Fields Summary
private static final int
ALIGNMENT
the required alignment for instances of this class
private static final int
ENTRY_WRITE_SIZE
the size of an entry int the set: one {@code uint}
private final com.android.dx.rop.annotation.Annotations
annotations
{@code non-null;} the set of annotations
private final AnnotationItem[]
items
{@code non-null;} set of annotations as individual items in an array. Note: The contents have to get sorted by type id before writing.
Constructors Summary
public AnnotationSetItem(com.android.dx.rop.annotation.Annotations annotations, DexFile dexFile)
Constructs an instance.

param
annotations {@code non-null;} set of annotations
param
dexFile {@code non-null;} dex output


                         
         
        super(ALIGNMENT, writeSize(annotations));

        this.annotations = annotations;
        this.items = new AnnotationItem[annotations.size()];

        int at = 0;
        for (Annotation a : annotations.getAnnotations()) {
            items[at] = new AnnotationItem(a, dexFile);
            at++;
        }
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

        MixedItemSection byteData = file.getByteData();
        int size = items.length;

        for (int i = 0; i < size; i++) {
            items[i] = byteData.intern(items[i]);
        }
    
protected intcompareTo0(OffsettedItem other)
{@inheritDoc}

        AnnotationSetItem otherSet = (AnnotationSetItem) other;

        return annotations.compareTo(otherSet.annotations);
    
public com.android.dx.rop.annotation.AnnotationsgetAnnotations()
Gets the underlying annotations of this instance

return
{@code non-null;} the annotations

        return annotations;
    
public inthashCode()
{@inheritDoc}

        return annotations.hashCode();
    
public ItemTypeitemType()
{@inheritDoc}

        return ItemType.TYPE_ANNOTATION_SET_ITEM;
    
protected voidplace0(Section addedTo, int offset)
{@inheritDoc}

        // Sort the array to be in type id index order.
        AnnotationItem.sortByTypeIdIndex(items);
    
public java.lang.StringtoHuman()
{@inheritDoc}

        return annotations.toString();
    
private static intwriteSize(com.android.dx.rop.annotation.Annotations annotations)
Gets the write size for the given set.

param
annotations {@code non-null;} the set
return
{@code > 0;} the write size

        // This includes an int size at the start of the list.

        try {
            return (annotations.size() * ENTRY_WRITE_SIZE) + 4;
        } catch (NullPointerException ex) {
            // Elucidate the exception.
            throw new NullPointerException("list == null");
        }
    
protected voidwriteTo0(DexFile file, com.android.dx.util.AnnotatedOutput out)
{@inheritDoc}

        boolean annotates = out.annotates();
        int size = items.length;

        if (annotates) {
            out.annotate(0, offsetString() + " annotation set");
            out.annotate(4, "  size: " + Hex.u4(size));
        }

        out.writeInt(size);

        for (int i = 0; i < size; i++) {
            AnnotationItem item = items[i];
            int offset = item.getAbsoluteOffset();

            if (annotates) {
                out.annotate(4, "  entries[" + Integer.toHexString(i) + "]: " +
                        Hex.u4(offset));
                items[i].annotateTo(out, "    ");
            }

            out.writeInt(offset);
        }