Search in sources :

Example 1 with DefaultQualifierInHierarchy

use of org.checkerframework.framework.qual.DefaultQualifierInHierarchy in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method addCheckedCodeDefaults.

/**
 * Adds default qualifiers for type-checked code by reading {@link DefaultFor} and {@link
 * DefaultQualifierInHierarchy} meta-annotations. Subclasses may override this method to add
 * defaults that cannot be specified with a {@link DefaultFor} or {@link
 * DefaultQualifierInHierarchy} meta-annotations.
 *
 * @param defs QualifierDefault object to which defaults are added
 */
protected void addCheckedCodeDefaults(QualifierDefaults defs) {
    boolean foundOtherwise = false;
    // Add defaults from @DefaultFor and @DefaultQualifierInHierarchy
    for (Class<? extends Annotation> qual : getSupportedTypeQualifiers()) {
        DefaultFor defaultFor = qual.getAnnotation(DefaultFor.class);
        if (defaultFor != null) {
            final TypeUseLocation[] locations = defaultFor.value();
            defs.addCheckedCodeDefaults(AnnotationBuilder.fromClass(elements, qual), locations);
            foundOtherwise = foundOtherwise || Arrays.asList(locations).contains(TypeUseLocation.OTHERWISE);
        }
        if (qual.getAnnotation(DefaultQualifierInHierarchy.class) != null) {
            defs.addCheckedCodeDefault(AnnotationBuilder.fromClass(elements, qual), TypeUseLocation.OTHERWISE);
            foundOtherwise = true;
        }
    }
    // If Unqualified is a supported qualifier, make it the default.
    AnnotationMirror unqualified = AnnotationBuilder.fromClass(elements, Unqualified.class);
    if (!foundOtherwise && this.isSupportedQualifier(unqualified)) {
        defs.addCheckedCodeDefault(unqualified, TypeUseLocation.OTHERWISE);
    }
}
Also used : TypeUseLocation(org.checkerframework.framework.qual.TypeUseLocation) AnnotationMirror(javax.lang.model.element.AnnotationMirror) DefaultQualifierInHierarchy(org.checkerframework.framework.qual.DefaultQualifierInHierarchy) DefaultFor(org.checkerframework.framework.qual.DefaultFor)

Aggregations

AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 DefaultFor (org.checkerframework.framework.qual.DefaultFor)1 DefaultQualifierInHierarchy (org.checkerframework.framework.qual.DefaultQualifierInHierarchy)1 TypeUseLocation (org.checkerframework.framework.qual.TypeUseLocation)1