當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。