sun.reflect.ConstantPool Java Examples

The following examples show how to use sun.reflect.ConstantPool. 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: AnnotationParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseBooleanArray(int length,
                                 ByteBuffer buf, ConstantPool constPool) {
    boolean[] result = new boolean[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'Z') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (constPool.getIntAt(index) != 0);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #2
Source File: AnnotationParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseClassArray(int length,
                                      ByteBuffer buf,
                                      ConstantPool constPool,
                                      Class<?> container) {
    Object[] result = new Class<?>[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'c') {
            result[i] = parseClassValue(buf, constPool, container);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #3
Source File: TypeAnnotationParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build an AnnotatedType from the parameters supplied.
 *
 * This method and {@code buildAnnotatedTypes} 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 type the type the AnnotatedType corresponds to
 * @param filter the type annotation targets included in this AnnotatedType
 */
public static AnnotatedType buildAnnotatedType(byte[] rawAnnotations,
        ConstantPool cp,
        AnnotatedElement decl,
        Class<?> container,
        Type type,
        TypeAnnotationTarget filter) {
    TypeAnnotation[] tas = parseTypeAnnotations(rawAnnotations,
                                                cp,
                                                decl,
                                                container);
    List<TypeAnnotation> l = new ArrayList<>(tas.length);
    for (TypeAnnotation t : tas) {
        TypeAnnotationTargetInfo ti = t.getTargetInfo();
        if (ti.getTarget() == filter)
            l.add(t);
    }
    TypeAnnotation[] typeAnnotations = l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
    return AnnotatedTypeFactory.buildAnnotatedType(type,
                                                   LocationInfo.BASE_LOCATION,
                                                   typeAnnotations,
                                                   typeAnnotations,
                                                   decl);
}
 
Example #4
Source File: AnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static Annotation[][] parseParameterAnnotations2(
                byte[] rawAnnotations,
                ConstantPool constPool,
                Class<?> container) {
    ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
    int numParameters = buf.get() & 0xFF;
    Annotation[][] result = new Annotation[numParameters][];

    for (int i = 0; i < numParameters; i++) {
        int numAnnotations = buf.getShort() & 0xFFFF;
        List<Annotation> annotations =
            new ArrayList<Annotation>(numAnnotations);
        for (int j = 0; j < numAnnotations; j++) {
            Annotation a = parseAnnotation(buf, constPool, container, false);
            if (a != null) {
                AnnotationType type = AnnotationType.getInstance(
                                          a.annotationType());
                if (type.retention() == RetentionPolicy.RUNTIME)
                    annotations.add(a);
            }
        }
        result[i] = annotations.toArray(EMPTY_ANNOTATIONS_ARRAY);
    }
    return result;
}
 
Example #5
Source File: AnnotationParser.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the enum constant member value at the current position in the
 * specified byte buffer, resolving constant references in the specified
 * constant pool.  The cursor of the byte buffer must point to a
 * "enum_const_value structure" as described in the
 * RuntimeVisibleAnnotations_attribute:
 *
 *       {
 *           u2   type_name_index;
 *           u2   const_name_index;
 *       } enum_const_value;
 */
private static Object parseEnumValue(Class enumType, ByteBuffer buf,
                                     ConstantPool constPool,
                                     Class container) {
    int typeNameIndex = buf.getShort() & 0xFFFF;
    String typeName  = constPool.getUTF8At(typeNameIndex);
    int constNameIndex = buf.getShort() & 0xFFFF;
    String constName = constPool.getUTF8At(constNameIndex);

    if (!typeName.endsWith(";")) {
        // support now-obsolete early jsr175-format class files.
        if (!enumType.getName().equals(typeName))
        return new AnnotationTypeMismatchExceptionProxy(
            typeName + "." + constName);
    } else if (enumType != parseSig(typeName, container)) {
        return new AnnotationTypeMismatchExceptionProxy(
            typeName + "." + constName);
    }

    try {
        return  Enum.valueOf(enumType, constName);
    } catch(IllegalArgumentException e) {
        return new EnumConstantNotPresentExceptionProxy(
            (Class<? extends Enum>)enumType, constName);
    }
}
 
Example #6
Source File: AnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseIntArray(int length,
                             ByteBuffer buf, ConstantPool constPool) {
    int[] result = new  int[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'I') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = constPool.getIntAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #7
Source File: AnnotationParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseCharArray(int length,
                              ByteBuffer buf, ConstantPool constPool) {
    char[] result = new char[length];
    boolean typeMismatch = false;
    byte tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'C') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (char) constPool.getIntAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #8
Source File: AnnotationParser.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseByteArray(int length,
                              ByteBuffer buf, ConstantPool constPool) {
    byte[] result = new byte[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'B') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (byte) constPool.getIntAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #9
Source File: AnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseBooleanArray(int length,
                                 ByteBuffer buf, ConstantPool constPool) {
    boolean[] result = new boolean[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'Z') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (constPool.getIntAt(index) != 0);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #10
Source File: TypeAnnotationParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build an array of AnnotatedTypes for the class decl's implemented
 * interfaces.
 *
 * @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 Class whose annotated implemented interfaces is being built
 */
public static AnnotatedType[] buildAnnotatedInterfaces(byte[] rawAnnotations,
        ConstantPool cp,
        Class<?> decl) {
    if (decl == Object.class ||
            decl.isArray() ||
            decl.isPrimitive() ||
            decl == Void.TYPE)
        return AnnotatedTypeFactory.EMPTY_ANNOTATED_TYPE_ARRAY;
    return buildAnnotatedTypes(rawAnnotations,
                               cp,
                               decl,
                               decl,
                               decl.getGenericInterfaces(),
                               TypeAnnotationTarget.CLASS_IMPLEMENTS);
}
 
Example #11
Source File: TypeAnnotationParser.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build an AnnotatedType from the parameters supplied.
 *
 * This method and {@code buildAnnotatedTypes} 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 type the type the AnnotatedType corresponds to
 * @param filter the type annotation targets included in this AnnotatedType
 */
public static AnnotatedType buildAnnotatedType(byte[] rawAnnotations,
        ConstantPool cp,
        AnnotatedElement decl,
        Class<?> container,
        Type type,
        TypeAnnotationTarget filter) {
    TypeAnnotation[] tas = parseTypeAnnotations(rawAnnotations,
                                                cp,
                                                decl,
                                                container);
    List<TypeAnnotation> l = new ArrayList<>(tas.length);
    for (TypeAnnotation t : tas) {
        TypeAnnotationTargetInfo ti = t.getTargetInfo();
        if (ti.getTarget() == filter)
            l.add(t);
    }
    TypeAnnotation[] typeAnnotations = l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
    return AnnotatedTypeFactory.buildAnnotatedType(type,
                                                   LocationInfo.BASE_LOCATION,
                                                   typeAnnotations,
                                                   typeAnnotations,
                                                   decl);
}
 
Example #12
Source File: AnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseEnumArray(int length, Class<? extends Enum<?>> enumType,
                                     ByteBuffer buf,
                                     ConstantPool constPool,
                                     Class<?> container) {
    Object[] result = (Object[]) Array.newInstance(enumType, length);
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'e') {
            result[i] = parseEnumValue(enumType, buf, constPool, container);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #13
Source File: AnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseDoubleArray(int length,
                                ByteBuffer buf, ConstantPool constPool) {
    double[] result = new  double[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'D') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = constPool.getDoubleAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #14
Source File: AnnotationParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseShortArray(int length,
                               ByteBuffer buf, ConstantPool constPool) {
    short[] result = new short[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'S') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (short) constPool.getIntAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #15
Source File: TypeAnnotationParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static TypeAnnotation[] parseTypeAnnotations(byte[] rawAnnotations,
        ConstantPool cp,
        AnnotatedElement baseDecl,
        Class<?> container) {
    if (rawAnnotations == null)
        return EMPTY_TYPE_ANNOTATION_ARRAY;

    ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
    int annotationCount = buf.getShort() & 0xFFFF;
    List<TypeAnnotation> typeAnnotations = new ArrayList<>(annotationCount);

    // Parse each TypeAnnotation
    for (int i = 0; i < annotationCount; i++) {
         TypeAnnotation ta = parseTypeAnnotation(buf, cp, baseDecl, container);
         if (ta != null)
             typeAnnotations.add(ta);
    }

    return typeAnnotations.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
}
 
Example #16
Source File: TypeAnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static TypeAnnotation parseTypeAnnotation(ByteBuffer buf,
        ConstantPool cp,
        AnnotatedElement baseDecl,
        Class<?> container) {
    try {
        TypeAnnotationTargetInfo ti = parseTargetInfo(buf);
        LocationInfo locationInfo = LocationInfo.parseLocationInfo(buf);
        Annotation a = AnnotationParser.parseAnnotation(buf, cp, container, false);
        if (ti == null) // Inside a method for example
            return null;
        return new TypeAnnotation(ti, locationInfo, a, baseDecl);
    } catch (IllegalArgumentException | // Bad type in const pool at specified index
            BufferUnderflowException e) {
        throw new AnnotationFormatError(e);
    }
}
 
Example #17
Source File: AnnotationParser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseDoubleArray(int length,
                                ByteBuffer buf, ConstantPool constPool) {
    double[] result = new  double[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'D') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = constPool.getDoubleAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #18
Source File: AnnotationParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseStringArray(int length,
                                ByteBuffer buf,  ConstantPool constPool) {
    String[] result = new String[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 's') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = constPool.getUTF8At(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #19
Source File: AnnotationParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseClassArray(int length,
                                      ByteBuffer buf,
                                      ConstantPool constPool,
                                      Class<?> container) {
    Object[] result = new Class<?>[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'c') {
            result[i] = parseClassValue(buf, constPool, container);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #20
Source File: AnnotationParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseClassArray(int length,
                                      ByteBuffer buf,
                                      ConstantPool constPool,
                                      Class<?> container) {
    Object[] result = new Class<?>[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'c') {
            result[i] = parseClassValue(buf, constPool, container);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #21
Source File: AnnotationParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseStringArray(int length,
                                ByteBuffer buf,  ConstantPool constPool) {
    String[] result = new String[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 's') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = constPool.getUTF8At(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #22
Source File: AnnotationParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> parseAnnotations2(
            byte[] rawAnnotations,
            ConstantPool constPool,
            Class<?> container,
            Class<? extends Annotation>[] selectAnnotationClasses) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<Class<? extends Annotation>, Annotation>();
    ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
    int numAnnotations = buf.getShort() & 0xFFFF;
    for (int i = 0; i < numAnnotations; i++) {
        Annotation a = parseAnnotation2(buf, constPool, container, false, selectAnnotationClasses);
        if (a != null) {
            Class<? extends Annotation> klass = a.annotationType();
            if (AnnotationType.getInstance(klass).retention() == RetentionPolicy.RUNTIME &&
                result.put(klass, a) != null) {
                    throw new AnnotationFormatError(
                        "Duplicate annotation for class: "+klass+": " + a);
        }
    }
    }
    return result;
}
 
Example #23
Source File: TypeAnnotationParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build an array of AnnotatedTypes for the class decl's implemented
 * interfaces.
 *
 * @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 Class whose annotated implemented interfaces is being built
 */
public static AnnotatedType[] buildAnnotatedInterfaces(byte[] rawAnnotations,
        ConstantPool cp,
        Class<?> decl) {
    if (decl == Object.class ||
            decl.isArray() ||
            decl.isPrimitive() ||
            decl == Void.TYPE)
        return AnnotatedTypeFactory.EMPTY_ANNOTATED_TYPE_ARRAY;
    return buildAnnotatedTypes(rawAnnotations,
                               cp,
                               decl,
                               decl,
                               decl.getGenericInterfaces(),
                               TypeAnnotationTarget.CLASS_IMPLEMENTS);
}
 
Example #24
Source File: AnnotationParser.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private static Object parseStringArray(int length,
                                ByteBuffer buf,  ConstantPool constPool) {
    String[] result = new String[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 's') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = constPool.getUTF8At(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #25
Source File: AnnotationParser.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private static Object parseCharArray(int length,
                              ByteBuffer buf, ConstantPool constPool) {
    char[] result = new char[length];
    boolean typeMismatch = false;
    byte tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'C') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (char) constPool.getIntAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #26
Source File: AnnotationParser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Object parseShortArray(int length,
                               ByteBuffer buf, ConstantPool constPool) {
    short[] result = new short[length];
    boolean typeMismatch = false;
    int tag = 0;

    for (int i = 0; i < length; i++) {
        tag = buf.get();
        if (tag == 'S') {
            int index = buf.getShort() & 0xFFFF;
            result[i] = (short) constPool.getIntAt(index);
        } else {
            skipMemberValue(tag, buf);
            typeMismatch = true;
        }
    }
    return typeMismatch ? exceptionProxy(tag) : result;
}
 
Example #27
Source File: AnnotationParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static Annotation[][] parseParameterAnnotations2(
                byte[] rawAnnotations,
                ConstantPool constPool,
                Class<?> container) {
    ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
    int numParameters = buf.get() & 0xFF;
    Annotation[][] result = new Annotation[numParameters][];

    for (int i = 0; i < numParameters; i++) {
        int numAnnotations = buf.getShort() & 0xFFFF;
        List<Annotation> annotations =
            new ArrayList<Annotation>(numAnnotations);
        for (int j = 0; j < numAnnotations; j++) {
            Annotation a = parseAnnotation(buf, constPool, container, false);
            if (a != null) {
                AnnotationType type = AnnotationType.getInstance(
                                          a.annotationType());
                if (type.retention() == RetentionPolicy.RUNTIME)
                    annotations.add(a);
            }
        }
        result[i] = annotations.toArray(EMPTY_ANNOTATIONS_ARRAY);
    }
    return result;
}
 
Example #28
Source File: TypeAnnotationParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build an AnnotatedType from the parameters supplied.
 *
 * This method and {@code buildAnnotatedTypes} 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 type the type the AnnotatedType corresponds to
 * @param filter the type annotation targets included in this AnnotatedType
 */
public static AnnotatedType buildAnnotatedType(byte[] rawAnnotations,
        ConstantPool cp,
        AnnotatedElement decl,
        Class<?> container,
        Type type,
        TypeAnnotationTarget filter) {
    TypeAnnotation[] tas = parseTypeAnnotations(rawAnnotations,
                                                cp,
                                                decl,
                                                container);
    List<TypeAnnotation> l = new ArrayList<>(tas.length);
    for (TypeAnnotation t : tas) {
        TypeAnnotationTargetInfo ti = t.getTargetInfo();
        if (ti.getTarget() == filter)
            l.add(t);
    }
    TypeAnnotation[] typeAnnotations = l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
    return AnnotatedTypeFactory.buildAnnotatedType(type,
                                                   LocationInfo.BASE_LOCATION,
                                                   typeAnnotations,
                                                   typeAnnotations,
                                                   decl);
}
 
Example #29
Source File: AnnotationParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Annotation[][] parseParameterAnnotations2(
                byte[] rawAnnotations,
                ConstantPool constPool,
                Class<?> container) {
    ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
    int numParameters = buf.get() & 0xFF;
    Annotation[][] result = new Annotation[numParameters][];

    for (int i = 0; i < numParameters; i++) {
        int numAnnotations = buf.getShort() & 0xFFFF;
        List<Annotation> annotations =
            new ArrayList<Annotation>(numAnnotations);
        for (int j = 0; j < numAnnotations; j++) {
            Annotation a = parseAnnotation(buf, constPool, container, false);
            if (a != null) {
                AnnotationType type = AnnotationType.getInstance(
                                          a.annotationType());
                if (type.retention() == RetentionPolicy.RUNTIME)
                    annotations.add(a);
            }
        }
        result[i] = annotations.toArray(EMPTY_ANNOTATIONS_ARRAY);
    }
    return result;
}
 
Example #30
Source File: AnnotationParser.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses the enum constant member value at the current position in the
 * specified byte buffer, resolving constant references in the specified
 * constant pool.  The cursor of the byte buffer must point to a
 * "enum_const_value structure" as described in the
 * RuntimeVisibleAnnotations_attribute:
 *
 *       {
 *           u2   type_name_index;
 *           u2   const_name_index;
 *       } enum_const_value;
 */
private static Object parseEnumValue(Class enumType, ByteBuffer buf,
                                     ConstantPool constPool,
                                     Class container) {
    int typeNameIndex = buf.getShort() & 0xFFFF;
    String typeName  = constPool.getUTF8At(typeNameIndex);
    int constNameIndex = buf.getShort() & 0xFFFF;
    String constName = constPool.getUTF8At(constNameIndex);

    if (!typeName.endsWith(";")) {
        // support now-obsolete early jsr175-format class files.
        if (!enumType.getName().equals(typeName))
        return new AnnotationTypeMismatchExceptionProxy(
            typeName + "." + constName);
    } else if (enumType != parseSig(typeName, container)) {
        return new AnnotationTypeMismatchExceptionProxy(
            typeName + "." + constName);
    }

    try {
        return  Enum.valueOf(enumType, constName);
    } catch(IllegalArgumentException e) {
        return new EnumConstantNotPresentExceptionProxy(
            (Class<? extends Enum>)enumType, constName);
    }
}