Search in sources :

Example 6 with TypeAnnotation

use of sun.reflect.annotation.TypeAnnotation in project jdk8u_jdk by JetBrains.

the class TypeAnnotationParser method buildAnnotatedTypes.

/**
     * Build an array of AnnotatedTypes from the parameters supplied.
     *
     * This method and {@code buildAnnotatedType} are probably
     * the entry points you are looking for.
     *
     * @param rawAnnotations the byte[] encoding of all type annotations on this declaration
     * @param cp the ConstantPool needed to parse the embedded Annotation
     * @param decl the declaration this type annotation is on
     * @param container the Class this type annotation is on (may be the same as decl)
     * @param types the Types the AnnotatedTypes corresponds to
     * @param filter the type annotation targets that included in this AnnotatedType
     */
public static AnnotatedType[] buildAnnotatedTypes(byte[] rawAnnotations, ConstantPool cp, AnnotatedElement decl, Class<?> container, Type[] types, TypeAnnotationTarget filter) {
    int size = types.length;
    AnnotatedType[] result = new AnnotatedType[size];
    Arrays.fill(result, AnnotatedTypeFactory.EMPTY_ANNOTATED_TYPE);
    @SuppressWarnings("rawtypes") ArrayList[] // array of ArrayList<TypeAnnotation>
    l = new ArrayList[size];
    TypeAnnotation[] tas = parseTypeAnnotations(rawAnnotations, cp, decl, container);
    for (TypeAnnotation t : tas) {
        TypeAnnotationTargetInfo ti = t.getTargetInfo();
        if (ti.getTarget() == filter) {
            int pos = ti.getCount();
            if (l[pos] == null) {
                ArrayList<TypeAnnotation> tmp = new ArrayList<>(tas.length);
                l[pos] = tmp;
            }
            @SuppressWarnings("unchecked") ArrayList<TypeAnnotation> tmp = l[pos];
            tmp.add(t);
        }
    }
    for (int i = 0; i < size; i++) {
        @SuppressWarnings("unchecked") ArrayList<TypeAnnotation> list = l[i];
        TypeAnnotation[] typeAnnotations;
        if (list != null) {
            typeAnnotations = list.toArray(new TypeAnnotation[list.size()]);
        } else {
            typeAnnotations = EMPTY_TYPE_ANNOTATION_ARRAY;
        }
        result[i] = AnnotatedTypeFactory.buildAnnotatedType(types[i], LocationInfo.BASE_LOCATION, typeAnnotations, typeAnnotations, decl);
    }
    return result;
}
Also used : TypeAnnotation(sun.reflect.annotation.TypeAnnotation) ArrayList(java.util.ArrayList)

Example 7 with TypeAnnotation

use of sun.reflect.annotation.TypeAnnotation in project jdk8u_jdk by JetBrains.

the class TypeAnnotationParser method parseAnnotatedBounds.

//helper for above
private static <D extends GenericDeclaration> AnnotatedType[] parseAnnotatedBounds(Type[] bounds, D decl, int typeVarIndex, LocationInfo loc) {
    List<TypeAnnotation> candidates = fetchBounds(decl);
    if (bounds != null) {
        int startIndex = 0;
        AnnotatedType[] res = new AnnotatedType[bounds.length];
        // index 1.
        if (bounds.length > 0) {
            Type b0 = bounds[0];
            if (!(b0 instanceof Class<?>)) {
                startIndex = 1;
            } else {
                Class<?> c = (Class<?>) b0;
                if (c.isInterface()) {
                    startIndex = 1;
                }
            }
        }
        for (int i = 0; i < bounds.length; i++) {
            List<TypeAnnotation> l = new ArrayList<>(candidates.size());
            for (TypeAnnotation t : candidates) {
                TypeAnnotationTargetInfo tInfo = t.getTargetInfo();
                if (tInfo.getSecondaryIndex() == i + startIndex && tInfo.getCount() == typeVarIndex) {
                    l.add(t);
                }
            }
            res[i] = AnnotatedTypeFactory.buildAnnotatedType(bounds[i], loc, l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY), candidates.toArray(EMPTY_TYPE_ANNOTATION_ARRAY), (AnnotatedElement) decl);
        }
        return res;
    }
    return new AnnotatedType[0];
}
Also used : TypeAnnotation(sun.reflect.annotation.TypeAnnotation) ArrayList(java.util.ArrayList)

Aggregations

TypeAnnotation (sun.reflect.annotation.TypeAnnotation)7 ArrayList (java.util.ArrayList)5 BufferUnderflowException (java.nio.BufferUnderflowException)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedHashMap (java.util.LinkedHashMap)1