• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AnnotationType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中sun.reflect.annotation.AnnotationType的典型用法代码示例。如果您正苦于以下问题:Java AnnotationType类的具体用法?Java AnnotationType怎么用?Java AnnotationType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AnnotationType类属于sun.reflect.annotation包,在下文中一共展示了AnnotationType类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getValue

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:AnnotationProxyMaker.java


示例2: getDefaultValue

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:Method.java


示例3: getDefaultValue

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:Method.java


示例4: mapAnnotations

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:TypeVariableImpl.java


示例5: getDefaultValue

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
/**
 * 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 sun.reflect.annotation.ExceptionProxy)
        throw new AnnotationFormatError("Invalid default: " + this);
    return result;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:29,代码来源:Method.java


示例6: getFieldExportName

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
public static String getFieldExportName(Field field) {
    if (!field.isPublic() || field.isSynthetic())
        return null;

    AnnotationEntry[] entries = field.getAnnotationEntries();

    for (AnnotationEntry annotationEntry : entries) {
        String translated = Signature.translate(annotationEntry.getAnnotationType());

        if (translated.equals(OJNIExclude.class.getName()))
            return null;

        if (translated.equals(OJNIExportName.class.getName())) {

            ElementValuePair[] elementValuePairs = annotationEntry.getElementValuePairs();

            AnnotationType annotationType = AnnotationType.getInstance(OJNIExportName.class);

            for (ElementValuePair elementValuePair : elementValuePairs) {

                if (annotationType.memberTypes().get(elementValuePair.getNameString()) != null) {
                    return elementValuePair.getValue().stringifyValue();
                }
            }
        }
    }

    return field.getName();
}
 
开发者ID:ashitikov,项目名称:Objective-JNI,代码行数:30,代码来源:Utils.java


示例7: getDefaultValue

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
/**
 * Returns the default value for the annotation member represented by
 * this <tt>Method</tt> 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 <tt>Method</tt> 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;
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:29,代码来源:Method.java


示例8: getAnnotationsByType

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
/**
 * Returns annotations that are <em>associated</em> with this element.
 *
 * If there are no annotations <em>associated</em> with this element, the return
 * value is an array of length 0.
 *
 * The difference between this method and {@link #getAnnotation(Class)}
 * is that this method detects if its argument is a <em>repeatable
 * annotation type</em> (JLS 9.6), and if so, attempts to find one or
 * more annotations of that type by "looking through" a container
 * annotation.
 *
 * The caller of this method is free to modify the returned array; it will
 * have no effect on the arrays returned to other callers.
 *
 * @implSpec The default implementation first calls {@link
 * #getDeclaredAnnotationsByType(Class)} passing {@code
 * annotationClass} as the argument. If the returned array has
 * length greater than zero, the array is returned. If the returned
 * array is zero-length and this {@code AnnotatedElement} is a
 * class and the argument type is an inheritable annotation type,
 * and the superclass of this {@code AnnotatedElement} is non-null,
 * then the returned result is the result of calling {@link
 * #getAnnotationsByType(Class)} on the superclass with {@code
 * annotationClass} as the argument. Otherwise, a zero-length
 * array is returned.
 *
 * @param <T> the type of the annotation to query for and return if present
 * @param annotationClass the Class object corresponding to the
 *        annotation type
 * @return all this element's annotations for the specified annotation type if
 *     associated with this element, else an array of length zero
 * @throws NullPointerException if the given annotation class is null
 * @since 1.8
 */
default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
     /*
      * Definition of associated: directly or indirectly present OR
      * neither directly nor indirectly present AND the element is
      * a Class, the annotation type is inheritable, and the
      * annotation type is associated with the superclass of the
      * element.
      */
     T[] result = getDeclaredAnnotationsByType(annotationClass);

     if (result.length == 0 && // Neither directly nor indirectly present
         this instanceof Class && // the element is a class
         AnnotationType.getInstance(annotationClass).isInherited()) { // Inheritable
         Class<?> superClass = ((Class<?>) this).getSuperclass();
         if (superClass != null) {
             // Determine if the annotation is associated with the
             // superclass
             result = superClass.getAnnotationsByType(annotationClass);
         }
     }

     return result;
 }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:59,代码来源:AnnotatedElement.java


示例9: getMethodExportInfo

import sun.reflect.annotation.AnnotationType; //导入依赖的package包/类
public static MethodExportInfo getMethodExportInfo(Method method) {
    MethodExportInfo result = new MethodExportInfo();

    if (!method.isPublic() || method.isAnnotation() || method.isSynthetic())
        return result;

    String name = method.getName();

    AnnotationEntry[] entries = method.getAnnotationEntries();

    for (AnnotationEntry annotationEntry : entries) {
        String translated = Signature.translate(annotationEntry.getAnnotationType());

        if (translated.equals(OJNIExclude.class.getName()))
            return result;

        if (translated.equals(OJNIExportName.class.getName())) {
            result.isCustom = true;

            ElementValuePair[] elementValuePairs = annotationEntry.getElementValuePairs();

            AnnotationType annotationType = AnnotationType.getInstance(OJNIExportName.class);

            for (ElementValuePair elementValuePair : elementValuePairs) {

                if (annotationType.memberTypes().get(elementValuePair.getNameString()) != null) {
                    name = elementValuePair.getValue().stringifyValue();
                }
            }
        }
    }

    result.name = name;

    return result;
}
 
开发者ID:ashitikov,项目名称:Objective-JNI,代码行数:37,代码来源:Utils.java



注:本文中的sun.reflect.annotation.AnnotationType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FragmentEvent类代码示例发布时间:2022-05-21
下一篇:
Java IResourceDescriptions类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap