Java Code Examples for com.android.dx.rop.annotation.Annotations

The following examples show how to use com.android.dx.rop.annotation.Annotations. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the annotations out of a given {@link AttributeList}. This
 * combines both visible and invisible annotations into a single
 * result set and also adds in a system annotation for the
 * {@code Signature} attribute if present.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getAnnotations(AttributeList attribs) {
    Annotations result = getAnnotations0(attribs);
    Annotation signature = getSignature(attribs);
    Annotation sourceDebugExtension = getSourceDebugExtension(attribs);

    if (signature != null) {
        result = Annotations.combine(result, signature);
    }

    if (sourceDebugExtension != null) {
        result = Annotations.combine(result, sourceDebugExtension);
    }

    return result;
}
 
Example 2
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for {@link #getAnnotations} which just gets the
 * existing annotations, per se.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
private static Annotations getAnnotations0(AttributeList attribs) {
    AttRuntimeVisibleAnnotations visible =
        (AttRuntimeVisibleAnnotations)
        attribs.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
    AttRuntimeInvisibleAnnotations invisible =
        (AttRuntimeInvisibleAnnotations)
        attribs.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);

    if (visible == null) {
        if (invisible == null) {
            return Annotations.EMPTY;
        }
        return invisible.getAnnotations();
    }

    if (invisible == null) {
        return visible.getAnnotations();
    }

    // Both are non-null, so combine them.

    return Annotations.combine(visible.getAnnotations(),
            invisible.getAnnotations());
}
 
Example 3
Source Project: Box   Source File: AnnotationParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses an annotation attribute, per se.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotations
 * @return {@code non-null;} the list of annotations read from the attribute
 * data
 */
public Annotations parseAnnotationAttribute(
        AnnotationVisibility visibility) {
    Annotations result;

    try {
        result = parseAnnotations(visibility);

        if (input.available() != 0) {
            throw new ParseException("extra data in attribute");
        }
    } catch (IOException ex) {
        // ByteArray.MyDataInputStream should never throw.
        throw new RuntimeException("shouldn't happen", ex);
    }

    return result;
}
 
Example 4
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for {@link #getAnnotations} which just gets the
 * existing annotations, per se.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
private static Annotations getAnnotations0(AttributeList attribs) {
    AttRuntimeVisibleAnnotations visible =
        (AttRuntimeVisibleAnnotations)
        attribs.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
    AttRuntimeInvisibleAnnotations invisible =
        (AttRuntimeInvisibleAnnotations)
        attribs.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);

    if (visible == null) {
        if (invisible == null) {
            return Annotations.EMPTY;
        }
        return invisible.getAnnotations();
    }

    if (invisible == null) {
        return visible.getAnnotations();
    }

    // Both are non-null, so combine them.

    return Annotations.combine(visible.getAnnotations(),
            invisible.getAnnotations());
}
 
Example 5
Source Project: buck   Source File: BaseAnnotations.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param attributeName {@code non-null;} the name of the attribute
 * @param annotations {@code non-null;} the list of annotations
 * @param byteLength {@code >= 0;} attribute data length in the original
 * classfile (not including the attribute header)
 */
public BaseAnnotations(String attributeName, Annotations annotations,
        int byteLength) {
    super(attributeName);

    try {
        if (annotations.isMutable()) {
            throw new MutabilityException("annotations.isMutable()");
        }
    } catch (NullPointerException ex) {
        // Translate the exception.
        throw new NullPointerException("annotations == null");
    }

    this.annotations = annotations;
    this.byteLength = byteLength;
}
 
Example 6
Source Project: Box   Source File: BaseAnnotations.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param attributeName {@code non-null;} the name of the attribute
 * @param annotations {@code non-null;} the list of annotations
 * @param byteLength {@code >= 0;} attribute data length in the original
 * classfile (not including the attribute header)
 */
public BaseAnnotations(String attributeName, Annotations annotations,
        int byteLength) {
    super(attributeName);

    try {
        if (annotations.isMutable()) {
            throw new MutabilityException("annotations.isMutable()");
        }
    } catch (NullPointerException ex) {
        // Translate the exception.
        throw new NullPointerException("annotations == null");
    }

    this.annotations = annotations;
    this.byteLength = byteLength;
}
 
Example 7
Source Project: J2ME-Loader   Source File: BaseAnnotations.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param attributeName {@code non-null;} the name of the attribute
 * @param annotations {@code non-null;} the list of annotations
 * @param byteLength {@code >= 0;} attribute data length in the original
 * classfile (not including the attribute header)
 */
public BaseAnnotations(String attributeName, Annotations annotations,
        int byteLength) {
    super(attributeName);

    try {
        if (annotations.isMutable()) {
            throw new MutabilityException("annotations.isMutable()");
        }
    } catch (NullPointerException ex) {
        // Translate the exception.
        throw new NullPointerException("annotations == null");
    }

    this.annotations = annotations;
    this.byteLength = byteLength;
}
 
Example 8
Source Project: J2ME-Loader   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the annotations out of a given {@link AttributeList}. This
 * combines both visible and invisible annotations into a single
 * result set and also adds in a system annotation for the
 * {@code Signature} attribute if present.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getAnnotations(AttributeList attribs) {
    Annotations result = getAnnotations0(attribs);
    Annotation signature = getSignature(attribs);
    Annotation sourceDebugExtension = getSourceDebugExtension(attribs);

    if (signature != null) {
        result = Annotations.combine(result, signature);
    }

    if (sourceDebugExtension != null) {
        result = Annotations.combine(result, sourceDebugExtension);
    }

    return result;
}
 
Example 9
Source Project: J2ME-Loader   Source File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for {@link #getAnnotations} which just gets the
 * existing annotations, per se.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
private static Annotations getAnnotations0(AttributeList attribs) {
    AttRuntimeVisibleAnnotations visible =
        (AttRuntimeVisibleAnnotations)
        attribs.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
    AttRuntimeInvisibleAnnotations invisible =
        (AttRuntimeInvisibleAnnotations)
        attribs.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);

    if (visible == null) {
        if (invisible == null) {
            return Annotations.EMPTY;
        }
        return invisible.getAnnotations();
    }

    if (invisible == null) {
        return visible.getAnnotations();
    }

    // Both are non-null, so combine them.

    return Annotations.combine(visible.getAnnotations(),
            invisible.getAnnotations());
}
 
Example 10
Source Project: J2ME-Loader   Source File: AnnotationParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses an annotation list.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotations
 * @return {@code non-null;} the list of annotations read from the attribute
 * data
 */
private Annotations parseAnnotations(AnnotationVisibility visibility)
        throws IOException {
    int count = input.readUnsignedShort();

    if (observer != null) {
        parsed(2, "num_annotations: " + Hex.u2(count));
    }

    Annotations annotations = new Annotations();

    for (int i = 0; i < count; i++) {
        if (observer != null) {
            parsed(0, "annotations[" + i + "]:");
            changeIndent(1);
        }

        Annotation annotation = parseAnnotation(visibility);
        annotations.add(annotation);

        if (observer != null) {
            observer.changeIndent(-1);
        }
    }

    annotations.setImmutable();
    return annotations;
}
 
Example 11
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given method, similar to {@link
 * #getAnnotations}, also including an annotation for the translation
 * of the method-specific attribute {@code Exceptions}.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getMethodAnnotations(Method method) {
    Annotations result = getAnnotations(method.getAttributes());
    TypeList exceptions = getExceptions(method);

    if (exceptions.size() != 0) {
        Annotation throwsAnnotation =
            AnnotationUtils.makeThrows(exceptions);
        result = Annotations.combine(result, throwsAnnotation);
    }

    return result;
}
 
Example 12
Source Project: Box   Source File: AnnotationSetItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param annotations {@code non-null;} set of annotations
 * @param dexFile {@code non-null;} dex output
 */
public AnnotationSetItem(Annotations annotations, DexFile dexFile) {
    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++;
    }
}
 
Example 13
Source Project: Box   Source File: AnnotationSetItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the write size for the given set.
 *
 * @param annotations {@code non-null;} the set
 * @return {@code > 0;} the write size
 */
private static int writeSize(Annotations annotations) {
    // 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");
    }
}
 
Example 14
Source Project: buck   Source File: AnnotationParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a list of annotation lists.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotations
 * @return {@code non-null;} the list of annotation lists read from the attribute
 * data
 */
private AnnotationsList parseAnnotationsList(
        AnnotationVisibility visibility) throws IOException {
    int count = input.readUnsignedByte();

    if (observer != null) {
        parsed(1, "num_parameters: " + Hex.u1(count));
    }

    AnnotationsList outerList = new AnnotationsList(count);

    for (int i = 0; i < count; i++) {
        if (observer != null) {
            parsed(0, "parameter_annotations[" + i + "]:");
            changeIndent(1);
        }

        Annotations annotations = parseAnnotations(visibility);
        outerList.set(i, annotations);

        if (observer != null) {
            observer.changeIndent(-1);
        }
    }

    outerList.setImmutable();
    return outerList;
}
 
Example 15
Source Project: Box   Source File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the direct annotations on this instance. These are annotations
 * made on the class, per se, as opposed to on one of its members.
 * It is only valid to call this method at most once per instance.
 *
 * @param annotations {@code non-null;} annotations to set for this class
 * @param dexFile {@code non-null;} dex output
 */
public void setClassAnnotations(Annotations annotations, DexFile dexFile) {
    if (annotations == null) {
        throw new NullPointerException("annotations == null");
    }

    if (classAnnotations != null) {
        throw new UnsupportedOperationException(
                "class annotations already set");
    }

    classAnnotations = new AnnotationSetItem(annotations, dexFile);
}
 
Example 16
Source Project: Box   Source File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a method annotations item to this instance.
 *
 * @param method {@code non-null;} method in question
 * @param annotations {@code non-null;} associated annotations to add
 * @param dexFile {@code non-null;} dex output
 */
public void addMethodAnnotations(CstMethodRef method,
        Annotations annotations, DexFile dexFile) {
    if (methodAnnotations == null) {
        methodAnnotations = new ArrayList<MethodAnnotationStruct>();
    }

    methodAnnotations.add(new MethodAnnotationStruct(method,
                    new AnnotationSetItem(annotations, dexFile)));
}
 
Example 17
Source Project: Box   Source File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the method annotations for a given method, if any. This is
 * meant for use by debugging / dumping code.
 *
 * @param method {@code non-null;} the method
 * @return {@code null-ok;} the method annotations, if any
 */
public Annotations getMethodAnnotations(CstMethodRef method) {
    if (methodAnnotations == null) {
        return null;
    }

    for (MethodAnnotationStruct item : methodAnnotations) {
        if (item.getMethod().equals(method)) {
            return item.getAnnotations();
        }
    }

    return null;
}
 
Example 18
Source Project: Box   Source File: ParameterAnnotationStruct.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} the method in question
 * @param annotationsList {@code non-null;} the associated annotations list
 * @param dexFile {@code non-null;} dex output
 */
public ParameterAnnotationStruct(CstMethodRef method,
        AnnotationsList annotationsList, DexFile dexFile) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (annotationsList == null) {
        throw new NullPointerException("annotationsList == null");
    }

    this.method = method;
    this.annotationsList = annotationsList;

    /*
     * Construct an item for the annotations list. TODO: This
     * requires way too much copying; fix it.
     */

    int size = annotationsList.size();
    ArrayList<AnnotationSetRefItem> arrayList = new
        ArrayList<AnnotationSetRefItem>(size);

    for (int i = 0; i < size; i++) {
        Annotations annotations = annotationsList.get(i);
        AnnotationSetItem item = new AnnotationSetItem(annotations, dexFile);
        arrayList.add(new AnnotationSetRefItem(item));
    }

    this.annotationsItem = new UniformListItem<AnnotationSetRefItem>(
            ItemType.TYPE_ANNOTATION_SET_REF_LIST, arrayList);
}
 
Example 19
Source Project: J2ME-Loader   Source File: StdAttributeFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeVisibleAnnotations} attribute.
 */
private Attribute runtimeVisibleAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    Annotations annotations =
        ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME);

    return new AttRuntimeVisibleAnnotations(annotations, length);
}
 
Example 20
Source Project: buck   Source File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given class, similar to {@link
 * #getAnnotations}, also including annotations for translations
 * of class-level attributes {@code EnclosingMethod} and
 * {@code InnerClasses}, if present. Additionally, if the
 * class is an annotation class, then this also includes a
 * representation of all the {@code AnnotationDefault}
 * values.
 *
 * @param cf {@code non-null;} the class in question
 * @param args {@code non-null;} the high-level options
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getClassAnnotations(DirectClassFile cf,
        CfOptions args) {
    CstType thisClass = cf.getThisClass();
    AttributeList attribs = cf.getAttributes();
    Annotations result = getAnnotations(attribs);
    Annotation enclosingMethod = translateEnclosingMethod(attribs);

    try {
        Annotations innerClassAnnotations =
            translateInnerClasses(thisClass, attribs,
                    enclosingMethod == null);
        if (innerClassAnnotations != null) {
            result = Annotations.combine(result, innerClassAnnotations);
        }
    } catch (Warning warn) {
        args.warn.println("warning: " + warn.getMessage());
    }

    if (enclosingMethod != null) {
        result = Annotations.combine(result, enclosingMethod);
    }

    if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
        Annotation annotationDefault =
            translateAnnotationDefaults(cf);
        if (annotationDefault != null) {
            result = Annotations.combine(result, annotationDefault);
        }
    }

    return result;
}
 
Example 21
Source Project: buck   Source File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given method, similar to {@link
 * #getAnnotations}, also including an annotation for the translation
 * of the method-specific attribute {@code Exceptions}.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getMethodAnnotations(Method method) {
    Annotations result = getAnnotations(method.getAttributes());
    TypeList exceptions = getExceptions(method);

    if (exceptions.size() != 0) {
        Annotation throwsAnnotation =
            AnnotationUtils.makeThrows(exceptions);
        result = Annotations.combine(result, throwsAnnotation);
    }

    return result;
}
 
Example 22
Source Project: Box   Source File: AnnotationParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a list of annotation lists.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotations
 * @return {@code non-null;} the list of annotation lists read from the attribute
 * data
 */
private AnnotationsList parseAnnotationsList(
        AnnotationVisibility visibility) throws IOException {
    int count = input.readUnsignedByte();

    if (observer != null) {
        parsed(1, "num_parameters: " + Hex.u1(count));
    }

    AnnotationsList outerList = new AnnotationsList(count);

    for (int i = 0; i < count; i++) {
        if (observer != null) {
            parsed(0, "parameter_annotations[" + i + "]:");
            changeIndent(1);
        }

        Annotations annotations = parseAnnotations(visibility);
        outerList.set(i, annotations);

        if (observer != null) {
            observer.changeIndent(-1);
        }
    }

    outerList.setImmutable();
    return outerList;
}
 
Example 23
Source Project: Box   Source File: AnnotationParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses an annotation list.
 *
 * @param visibility {@code non-null;} visibility of the parsed annotations
 * @return {@code non-null;} the list of annotations read from the attribute
 * data
 */
private Annotations parseAnnotations(AnnotationVisibility visibility)
        throws IOException {
    int count = input.readUnsignedShort();

    if (observer != null) {
        parsed(2, "num_annotations: " + Hex.u2(count));
    }

    Annotations annotations = new Annotations();

    for (int i = 0; i < count; i++) {
        if (observer != null) {
            parsed(0, "annotations[" + i + "]:");
            changeIndent(1);
        }

        Annotation annotation = parseAnnotation(visibility);
        annotations.add(annotation);

        if (observer != null) {
            observer.changeIndent(-1);
        }
    }

    annotations.setImmutable();
    return annotations;
}
 
Example 24
Source Project: Box   Source File: StdAttributeFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeInvisibleAnnotations} attribute.
 */
private Attribute runtimeInvisibleAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    Annotations annotations =
        ap.parseAnnotationAttribute(AnnotationVisibility.BUILD);

    return new AttRuntimeInvisibleAnnotations(annotations, length);
}
 
Example 25
Source Project: Box   Source File: StdAttributeFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses a {@code RuntimeVisibleAnnotations} attribute.
 */
private Attribute runtimeVisibleAnnotations(DirectClassFile cf,
        int offset, int length, ParseObserver observer) {
    if (length < 2) {
        throwSeverelyTruncated();
    }

    AnnotationParser ap =
        new AnnotationParser(cf, offset, length, observer);
    Annotations annotations =
        ap.parseAnnotationAttribute(AnnotationVisibility.RUNTIME);

    return new AttRuntimeVisibleAnnotations(annotations, length);
}
 
Example 26
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given class, similar to {@link
 * #getAnnotations}, also including annotations for translations
 * of class-level attributes {@code EnclosingMethod} and
 * {@code InnerClasses}, if present. Additionally, if the
 * class is an annotation class, then this also includes a
 * representation of all the {@code AnnotationDefault}
 * values.
 *
 * @param cf {@code non-null;} the class in question
 * @param args {@code non-null;} the high-level options
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getClassAnnotations(DirectClassFile cf,
        CfOptions args) {
    CstType thisClass = cf.getThisClass();
    AttributeList attribs = cf.getAttributes();
    Annotations result = getAnnotations(attribs);
    Annotation enclosingMethod = translateEnclosingMethod(attribs);

    try {
        Annotations innerClassAnnotations =
            translateInnerClasses(thisClass, attribs,
                    enclosingMethod == null);
        if (innerClassAnnotations != null) {
            result = Annotations.combine(result, innerClassAnnotations);
        }
    } catch (Warning warn) {
        args.warn.println("warning: " + warn.getMessage());
    }

    if (enclosingMethod != null) {
        result = Annotations.combine(result, enclosingMethod);
    }

    if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
        Annotation annotationDefault =
            translateAnnotationDefaults(cf);
        if (annotationDefault != null) {
            result = Annotations.combine(result, annotationDefault);
        }
    }

    return result;
}
 
Example 27
Source Project: Box   Source File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given method, similar to {@link
 * #getAnnotations}, also including an annotation for the translation
 * of the method-specific attribute {@code Exceptions}.
 *
 * @param method {@code non-null;} the method in question
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getMethodAnnotations(Method method) {
    Annotations result = getAnnotations(method.getAttributes());
    TypeList exceptions = getExceptions(method);

    if (exceptions.size() != 0) {
        Annotation throwsAnnotation =
            AnnotationUtils.makeThrows(exceptions);
        result = Annotations.combine(result, throwsAnnotation);
    }

    return result;
}
 
Example 28
Source Project: Box   Source File: AnnotationSetItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param annotations {@code non-null;} set of annotations
 * @param dexFile {@code non-null;} dex output
 */
public AnnotationSetItem(Annotations annotations, DexFile dexFile) {
    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++;
    }
}
 
Example 29
Source Project: buck   Source File: AttributeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the annotations out of a given {@link AttributeList}. This
 * combines both visible and invisible annotations into a single
 * result set and also adds in a system annotation for the
 * {@code Signature} attribute if present.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code non-null;} the set of annotations, which may be empty
 */
public static Annotations getAnnotations(AttributeList attribs) {
    Annotations result = getAnnotations0(attribs);
    Annotation signature = getSignature(attribs);

    if (signature != null) {
        result = Annotations.combine(result, signature);
    }

    return result;
}
 
Example 30
Source Project: Box   Source File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a field annotations item to this instance.
 *
 * @param field {@code non-null;} field in question
 * @param annotations {@code non-null;} associated annotations to add
 * @param dexFile {@code non-null;} dex output
 */
public void addFieldAnnotations(CstFieldRef field,
        Annotations annotations, DexFile dexFile) {
    if (fieldAnnotations == null) {
        fieldAnnotations = new ArrayList<FieldAnnotationStruct>();
    }

    fieldAnnotations.add(new FieldAnnotationStruct(field,
                    new AnnotationSetItem(annotations, dexFile)));
}