Search in sources :

Example 6 with TypeUseLocation

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

the class QualifierDefaults method fromDefaultQualifier.

private DefaultSet fromDefaultQualifier(DefaultQualifier dq) {
    // TODO: I want to simply write d.value(), but that doesn't work.
    // It works in other places, e.g. see handling of @SubtypeOf.
    // The hack below should probably be added to:
    // Class<? extends Annotation> cls = AnnotationUtils.parseTypeValue(dq, "value");
    Class<? extends Annotation> cls;
    try {
        cls = dq.value();
    } catch (MirroredTypeException mte) {
        try {
            @SuppressWarnings("unchecked") Class<? extends Annotation> clscast = (Class<? extends Annotation>) Class.forName(mte.getTypeMirror().toString());
            cls = clscast;
        } catch (ClassNotFoundException e) {
            ErrorReporter.errorAbort("Could not load qualifier: " + e.getMessage(), e);
            cls = null;
        }
    }
    AnnotationMirror anno = AnnotationBuilder.fromClass(elements, cls);
    if (anno == null) {
        return null;
    }
    if (!atypeFactory.isSupportedQualifier(anno)) {
        anno = atypeFactory.aliasedAnnotation(anno);
    }
    if (atypeFactory.isSupportedQualifier(anno)) {
        EnumSet<TypeUseLocation> locations = EnumSet.of(dq.locations()[0], dq.locations());
        DefaultSet ret = new DefaultSet();
        for (TypeUseLocation loc : locations) {
            ret.add(new Default(anno, loc));
        }
        return ret;
    } else {
        return null;
    }
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeUseLocation(org.checkerframework.framework.qual.TypeUseLocation) Annotation(java.lang.annotation.Annotation)

Example 7 with TypeUseLocation

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

the class QualifierDefaults method addUncheckedStandardDefaults.

/**
 * Add standard unchecked defaults that do not conflict with previously added defaults.
 */
public void addUncheckedStandardDefaults() {
    QualifierHierarchy qualHierarchy = this.atypeFactory.getQualifierHierarchy();
    Set<? extends AnnotationMirror> tops = qualHierarchy.getTopAnnotations();
    Set<? extends AnnotationMirror> bottoms = qualHierarchy.getBottomAnnotations();
    for (TypeUseLocation loc : standardUncheckedDefaultsTop) {
        // Only add standard defaults in locations where a default has not be specified
        for (AnnotationMirror top : tops) {
            if (!conflictsWithExistingDefaults(uncheckedCodeDefaults, top, loc)) {
                addUncheckedCodeDefault(top, loc);
            }
        }
    }
    for (TypeUseLocation loc : standardUncheckedDefaultsBottom) {
        for (AnnotationMirror bottom : bottoms) {
            // Only add standard defaults in locations where a default has not be specified
            if (!conflictsWithExistingDefaults(uncheckedCodeDefaults, bottom, loc)) {
                addUncheckedCodeDefault(bottom, loc);
            }
        }
    }
}
Also used : TypeUseLocation(org.checkerframework.framework.qual.TypeUseLocation) AnnotationMirror(javax.lang.model.element.AnnotationMirror) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy)

Aggregations

TypeUseLocation (org.checkerframework.framework.qual.TypeUseLocation)7 AnnotationMirror (javax.lang.model.element.AnnotationMirror)4 DefaultFor (org.checkerframework.framework.qual.DefaultFor)2 DefaultQualifierInHierarchy (org.checkerframework.framework.qual.DefaultQualifierInHierarchy)2 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)2 Annotation (java.lang.annotation.Annotation)1 Target (java.lang.annotation.Target)1 Element (javax.lang.model.element.Element)1 MirroredTypeException (javax.lang.model.type.MirroredTypeException)1 MirroredTypesException (javax.lang.model.type.MirroredTypesException)1 TypeKind (javax.lang.model.type.TypeKind)1 TypeMirror (javax.lang.model.type.TypeMirror)1 DefaultInUncheckedCodeFor (org.checkerframework.framework.qual.DefaultInUncheckedCodeFor)1 DefaultQualifier (org.checkerframework.framework.qual.DefaultQualifier)1 DefaultQualifierInHierarchyInUncheckedCode (org.checkerframework.framework.qual.DefaultQualifierInHierarchyInUncheckedCode)1 ImplicitFor (org.checkerframework.framework.qual.ImplicitFor)1 InvisibleQualifier (org.checkerframework.framework.qual.InvisibleQualifier)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1 AnnotatedArrayType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType)1 Annotation (scenelib.annotations.Annotation)1