当前位置: 首页>>代码示例>>Java>>正文


Java AnnotatedObject.getAnnotation方法代码示例

本文整理汇总了Java中edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedObject.getAnnotation方法的具体用法?Java AnnotatedObject.getAnnotation怎么用?Java AnnotatedObject.getAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject的用法示例。


在下文中一共展示了AnnotatedObject.getAnnotation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analysisContextContained

import edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject; //导入方法依赖的package包/类
private boolean analysisContextContained(XClass xclass) {
    AnnotatedObject ao = xclass;
    do {
        if (ao.getAnnotation(AnalysisContextContainedAnnotation) != null)
            return true;
        ao = ao.getContainingScope();

    } while (ao != null);
    return false;

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:12,代码来源:CheckAnalysisContextContainedAnnotation.java

示例2: checkFindBugsDefaultAnnotation

import edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject; //导入方法依赖的package包/类
private static @CheckForNull
TypeQualifierAnnotation checkFindBugsDefaultAnnotation(ClassDescriptor defaultAnnotation, AnnotatedObject o,
        TypeQualifierValue typeQualifierValue) {

    if (DEBUG_DEFAULT_ANNOTATION) {
        System.out.println("Checking for " + defaultAnnotation + " containing " + typeQualifierValue + " on " + o);
    }
    // - check to see if default annotation is present; if not, return null
    AnnotationValue annotationValue = o.getAnnotation(defaultAnnotation);
    if (annotationValue == null) {
        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("   ===> no " + defaultAnnotation);
        }
        return null;
    }

    // - get value - should be Type or array of Type
    Object value = annotationValue.getValue("value");
    if (value == null) {
        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("   ===> value is null");
        }
        return null;
    }
    Object[] types;
    if (value instanceof Object[]) {
        types = (Object[]) value;
    } else {
        types = new Object[] { value };
    }

    // - scan through array elements; see if any match the
    // TypeQualifierValue (including type qualifier nicknames)
    for (Object obj : types) {
        if (!(obj instanceof Type)) {
            if (DEBUG_DEFAULT_ANNOTATION) {
                System.out
                        .println("Found a non-Type value in value array of " + defaultAnnotation.toString() + " annotation");
            }
            continue;
        }

        Type type = (Type) obj;
        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("  ===> checking " + type.getDescriptor());
        }
        if (type.getDescriptor().startsWith("[")) {
            continue;
        }
        ClassDescriptor typeDesc = DescriptorFactory.instance().getClassDescriptor(type.getInternalName());

        // There is no general way to figure out whether a particular
        // type is a type qualifier we're interested in without
        // resolving it.
        AnnotationValue annotation = new AnnotationValue(typeDesc);
        Collection<AnnotationValue> resolvedTypeQualifiers = TypeQualifierResolver.resolveTypeQualifiers(annotation);
        TypeQualifierAnnotation tqa = extractAnnotation(resolvedTypeQualifiers, typeQualifierValue);
        if (tqa != null)
            return tqa;

    }

    return null;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:65,代码来源:TypeQualifierApplications.java

示例3: getDefaultAnnotation

import edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject; //导入方法依赖的package包/类
/**
 * Look for a default type qualifier annotation.
 *
 * @param o
 *            an AnnotatedObject
 * @param typeQualifierValue
 *            a TypeQualifierValue
 * @param elementType
 *            type of element for which we're looking for a default
 *            annotation
 * @return default TypeQualifierAnnotation, or null if none
 */
private static @CheckForNull
TypeQualifierAnnotation getDefaultAnnotation(AnnotatedObject o, TypeQualifierValue<?> typeQualifierValue, ElementType elementType) {
    //
    // Try to find a default annotation using the standard JSR-305
    // default annotation mechanism.
    //
    TypeQualifierAnnotation result;
    Collection<AnnotationValue> values = TypeQualifierResolver.resolveTypeQualifierDefaults(o.getAnnotations(), elementType);
    TypeQualifierAnnotation tqa = extractAnnotation(values, typeQualifierValue);

    if (tqa != null) {
        // System.out.println("Found default annotation of " + tqa +
        // " for element " + elementType + " in " + o);
        return tqa;
    }

    //
    // Try one of the FindBugs-specific default annotation mechanisms.
    //

    if ((result = checkFindBugsDefaultAnnotation(FindBugsDefaultAnnotations.DEFAULT_ANNOTATION, o, typeQualifierValue)) != null) {
        return result;
    }

    switch (elementType) {
    case FIELD:
        result = checkFindBugsDefaultAnnotation(FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_FIELDS, o,
                typeQualifierValue);
        break;
    case METHOD:
        result = checkFindBugsDefaultAnnotation(FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_METHODS, o,
                typeQualifierValue);
        break;
    case PARAMETER:
        result = checkFindBugsDefaultAnnotation(FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_PARAMETERS, o,
                typeQualifierValue);
        break;
    default:
        // ignore
    }

    // Try out default JDT (Eclipse) annotations
    if(result == null){
        AnnotationValue annotationValue = o.getAnnotation(TypeQualifierResolver.eclipseNonNullByDefault);
        if(annotationValue != null){
            Collection<AnnotationValue> resolvedTypeQualifiers = TypeQualifierResolver.resolveTypeQualifiers(annotationValue);
            tqa = extractAnnotation(resolvedTypeQualifiers, typeQualifierValue);
            if(tqa != null){
                return tqa;
            }
        }
    }
    return result;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:67,代码来源:TypeQualifierApplications.java

示例4: checkFindBugsDefaultAnnotation

import edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject; //导入方法依赖的package包/类
private static @CheckForNull
TypeQualifierAnnotation checkFindBugsDefaultAnnotation(ClassDescriptor defaultAnnotation, AnnotatedObject o,
        TypeQualifierValue<?> typeQualifierValue) {

    if (DEBUG_DEFAULT_ANNOTATION) {
        System.out.println("Checking for " + defaultAnnotation + " containing " + typeQualifierValue + " on " + o);
    }
    // - check to see if default annotation is present; if not, return null
    AnnotationValue annotationValue = o.getAnnotation(defaultAnnotation);
    if (annotationValue == null) {
        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("   ===> no " + defaultAnnotation);
        }
        return null;
    }

    // - get value - should be Type or array of Type
    Object value = annotationValue.getValue("value");
    if (value == null) {
        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("   ===> value is null");
        }
        return null;
    }
    Object[] types;
    if (value instanceof Object[]) {
        types = (Object[]) value;
    } else {
        types = new Object[] { value };
    }

    // - scan through array elements; see if any match the
    // TypeQualifierValue (including type qualifier nicknames)
    for (Object obj : types) {
        if (!(obj instanceof Type)) {
            if (DEBUG_DEFAULT_ANNOTATION) {
                System.out
                        .println("Found a non-Type value in value array of " + defaultAnnotation.toString() + " annotation");
            }
            continue;
        }

        Type type = (Type) obj;
        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("  ===> checking " + type.getDescriptor());
        }
        if (type.getDescriptor().startsWith("[")) {
            continue;
        }
        ClassDescriptor typeDesc = DescriptorFactory.instance().getClassDescriptor(type.getInternalName());

        // There is no general way to figure out whether a particular
        // type is a type qualifier we're interested in without
        // resolving it.
        AnnotationValue annotation = new AnnotationValue(typeDesc);
        Collection<AnnotationValue> resolvedTypeQualifiers = TypeQualifierResolver.resolveTypeQualifiers(annotation);
        TypeQualifierAnnotation tqa = extractAnnotation(resolvedTypeQualifiers, typeQualifierValue);
        if (tqa != null)
            return tqa;

    }

    return null;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:65,代码来源:TypeQualifierApplications.java


注:本文中的edu.umd.cs.findbugs.classfile.analysis.AnnotatedObject.getAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。