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

The following examples show how to use com.android.dx.rop.annotation.Annotations. 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 File: AttributeTranslator.java    From Box with 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 File: BaseAnnotations.java    From J2ME-Loader with 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 #3
Source File: BaseAnnotations.java    From Box with 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 #4
Source File: AnnotationParser.java    From Box with 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 #5
Source File: AttributeTranslator.java    From J2ME-Loader with 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 #6
Source File: AttributeTranslator.java    From J2ME-Loader with 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 #7
Source File: BaseAnnotations.java    From buck with 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 File: AttributeTranslator.java    From Box with 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 #9
Source File: AttributeTranslator.java    From Box with 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 File: StdAttributeFactory.java    From buck with 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 #11
Source File: StdAttributeFactory.java    From Box with 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 #12
Source File: AnnotationSetItem.java    From J2ME-Loader with 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 File: ParameterAnnotationStruct.java    From buck with 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 #14
Source File: AnnotationsDirectoryItem.java    From J2ME-Loader with 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 #15
Source File: AnnotationsDirectoryItem.java    From J2ME-Loader with 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)));
}
 
Example #16
Source File: AnnotationsDirectoryItem.java    From J2ME-Loader with 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 File: AnnotationSetItem.java    From Box with 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 #18
Source File: AnnotationId.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add this annotation to a method.
 *
 * @param dexMaker DexMaker instance.
 * @param method   Method to be added to.
 */
public static void addToMethod(DexMaker dexMaker, MethodId<?, ?> method,List<AnnotationId<?,?>> ids) {
    ClassDefItem classDefItem = dexMaker.getTypeDeclaration(method.declaringType).toClassDefItem();

    if (classDefItem == null) {
        throw new NullPointerException("No class defined item is found");
    }
    CstMethodRef cstMethodRef = method.constant;
    if (cstMethodRef == null) {
        throw new NullPointerException("Method reference is NULL");
    }
    Annotations annotations = new Annotations();
    for (AnnotationId<?, ?> id :
            ids) {
        if (id.annotatedElement != ElementType.METHOD) {
            throw new IllegalStateException("This annotation is not for method");
        }

        if (method.declaringType != id.declaringType) {
            throw new IllegalArgumentException("Method" + method + "'s declaring type is inconsistent with" + id);
        }

        // Generate CstType
        CstType cstType = CstType.intern(id.type.ropType);

        // Generate Annotation
        Annotation annotation = new Annotation(cstType, AnnotationVisibility.RUNTIME);

        // Add generated annotation
        for (NameValuePair nvp : id.elements.values()) {
            annotation.add(nvp);
        }
        annotations.add(annotation);
    }
    classDefItem.addMethodAnnotations(cstMethodRef, annotations, dexMaker.getDexFile());


}
 
Example #19
Source File: AnnotationsDirectoryItem.java    From J2ME-Loader with 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 #20
Source File: AnnotationParser.java    From buck with 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 #21
Source File: AnnotationsDirectoryItem.java    From buck with 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)));
}
 
Example #22
Source File: AnnotationsDirectoryItem.java    From buck with 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 #23
Source File: AnnotationId.java    From dexmaker with Apache License 2.0 5 votes vote down vote up
/**
 * Add this annotation to a method.
 *
 * @param dexMaker DexMaker instance.
 * @param method Method to be added to.
 */
public void addToMethod(DexMaker dexMaker, MethodId<?, ?> method) {
    if (annotatedElement != ElementType.METHOD) {
        throw new IllegalStateException("This annotation is not for method");
    }

    if (!method.declaringType.equals(declaringType)) {
        throw new IllegalArgumentException("Method" + method + "'s declaring type is inconsistent with" + this);
    }

    ClassDefItem classDefItem = dexMaker.getTypeDeclaration(declaringType).toClassDefItem();

    if (classDefItem == null) {
        throw new NullPointerException("No class defined item is found");
    } else {
        CstMethodRef cstMethodRef = method.constant;

        if (cstMethodRef == null) {
            throw new NullPointerException("Method reference is NULL");
        } else {
            // Generate CstType
            CstType cstType = CstType.intern(type.ropType);

            // Generate Annotation
            Annotation annotation = new Annotation(cstType, AnnotationVisibility.RUNTIME);

            // Add generated annotation
            Annotations annotations = new Annotations();
            for (NameValuePair nvp : elements.values()) {
                annotation.add(nvp);
            }
            annotations.add(annotation);
            classDefItem.addMethodAnnotations(cstMethodRef, annotations, dexMaker.getDexFile());
        }
    }
}
 
Example #24
Source File: StdAttributeFactory.java    From buck with 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 File: ParameterAnnotationStruct.java    From Box with 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 #26
Source File: AnnotationsDirectoryItem.java    From Box with 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 #27
Source File: AnnotationsDirectoryItem.java    From Box with 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 #28
Source File: AnnotationsDirectoryItem.java    From Box with 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)));
}
 
Example #29
Source File: AttributeTranslator.java    From buck with 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 File: AnnotationParser.java    From J2ME-Loader with 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;
}