sun.reflect.annotation.AnnotationType Java Examples

The following examples show how to use sun.reflect.annotation.AnnotationType. 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: AnnotationProxyMaker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
Object getValue(Attribute attr) {
    Method method;              // runtime method of annotation element
    try {
        method = annoType.getMethod(meth.name.toString());
    } catch (NoSuchMethodException e) {
        return null;
    }
    returnClass = method.getReturnType();
    attr.accept(this);
    if (!(value instanceof ExceptionProxy) &&
        !AnnotationType.invocationHandlerReturnType(returnClass)
                                                .isInstance(value)) {
        typeMismatch(method, attr);
    }
    return value;
}
 
Example #2
Source File: AnnotationProxyMaker.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
Object getValue(Attribute attr) {
    Method method;              // runtime method of annotation element
    try {
        method = annoType.getMethod(meth.name.toString());
    } catch (NoSuchMethodException e) {
        return null;
    }
    returnClass = method.getReturnType();
    attr.accept(this);
    if (!(value instanceof ExceptionProxy) &&
        !AnnotationType.invocationHandlerReturnType(returnClass)
                                                .isInstance(value)) {
        typeMismatch(method, attr);
    }
    return value;
}
 
Example #3
Source File: Method.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof ExceptionProxy) {
        if (result instanceof TypeNotPresentExceptionProxy) {
            TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result;
            throw new TypeNotPresentException(proxy.typeName(), proxy.getCause());
        }
        throw new AnnotationFormatError("Invalid default: " + this);
    }
    return result;
}
 
Example #4
Source File: Method.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof ExceptionProxy) {
        if (result instanceof TypeNotPresentExceptionProxy) {
            TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result;
            throw new TypeNotPresentException(proxy.typeName(), proxy.getCause());
        }
        throw new AnnotationFormatError("Invalid default: " + this);
    }
    return result;
}
 
Example #5
Source File: Method.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #6
Source File: TypeVariableImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #7
Source File: Method.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #8
Source File: TypeVariableImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #9
Source File: Method.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #10
Source File: Method.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #11
Source File: TypeVariableImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #12
Source File: Method.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #13
Source File: TypeVariableImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #14
Source File: TypeVariableImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #15
Source File: TypeVariableImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #16
Source File: Method.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #17
Source File: TypeVariableImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #18
Source File: Method.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #19
Source File: Method.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #20
Source File: TypeVariableImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #21
Source File: Method.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #22
Source File: TypeVariableImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #23
Source File: Method.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #24
Source File: TypeVariableImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #25
Source File: Method.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #26
Source File: TypeVariableImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #27
Source File: Method.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #28
Source File: TypeVariableImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}
 
Example #29
Source File: Method.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default value for the annotation member represented by
 * this {@code Method} instance.  If the member is of a primitive type,
 * an instance of the corresponding wrapper type is returned. Returns
 * null if no default is associated with the member, or if the method
 * instance does not represent a declared member of an annotation type.
 *
 * @return the default value for the annotation member represented
 *     by this {@code Method} instance.
 * @throws TypeNotPresentException if the annotation is of type
 *     {@link Class} and no definition can be found for the
 *     default class value.
 * @since  1.5
 */
public Object getDefaultValue() {
    if  (annotationDefault == null)
        return null;
    Class<?> memberType = AnnotationType.invocationHandlerReturnType(
        getReturnType());
    Object result = AnnotationParser.parseMemberValue(
        memberType, ByteBuffer.wrap(annotationDefault),
        sun.misc.SharedSecrets.getJavaLangAccess().
            getConstantPool(getDeclaringClass()),
        getDeclaringClass());
    if (result instanceof sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
Example #30
Source File: TypeVariableImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
    Map<Class<? extends Annotation>, Annotation> result =
        new LinkedHashMap<>();
    for (Annotation a : annos) {
        Class<? extends Annotation> klass = a.annotationType();
        AnnotationType type = AnnotationType.getInstance(klass);
        if (type.retention() == RetentionPolicy.RUNTIME)
            if (result.put(klass, a) != null)
                throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
    }
    return result;
}