Java Code Examples for sun.reflect.annotation.AnnotationType

The following examples show how to use sun.reflect.annotation.AnnotationType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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 Project: javaide   Source File: AnnotationProxyMaker.java    License: 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 Project: Bytecoder   Source File: Method.java    License: 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 Project: openjdk-jdk9   Source File: Method.java    License: 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 Project: jdk1.8-source-analysis   Source File: Method.java    License: 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 6
Source Project: dragonwell8_jdk   Source File: Method.java    License: 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 7
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 8
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 Project: jdk8u60   Source File: Method.java    License: 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 Project: jdk8u60   Source File: TypeVariableImpl.java    License: 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 11
Source Project: JDKSourceCode1.8   Source File: Method.java    License: 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 12
Source Project: openjdk-jdk8u   Source File: Method.java    License: 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
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 Project: openjdk-jdk8u-backup   Source File: Method.java    License: 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 15
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 Project: Bytecoder   Source File: TypeVariableImpl.java    License: 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 17
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 Project: jdk8u-jdk   Source File: Method.java    License: 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 19
Source Project: jdk8u-jdk   Source File: TypeVariableImpl.java    License: 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 20
Source Project: Java8CN   Source File: Method.java    License: 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 21
Source Project: hottub   Source File: Method.java    License: 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 Project: hottub   Source File: TypeVariableImpl.java    License: 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 Project: openjdk-8-source   Source File: Method.java    License: 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
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 Project: openjdk-8   Source File: Method.java    License: 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 Project: openjdk-8   Source File: TypeVariableImpl.java    License: 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 Project: jdk8u_jdk   Source File: Method.java    License: 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 Project: jdk8u_jdk   Source File: TypeVariableImpl.java    License: 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 Project: jdk8u-jdk   Source File: Method.java    License: 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 30
Source Project: jdk8u-jdk   Source File: TypeVariableImpl.java    License: 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;
}