Search in sources :

Example 11 with QualifierHierarchy

use of org.checkerframework.framework.type.QualifierHierarchy in project checker-framework by typetools.

the class InitializationStore method insertValue.

/**
 * {@inheritDoc}
 *
 * <p>If the receiver is a field, and has an invariant annotation, then it can be considered
 * initialized.
 */
@Override
public void insertValue(Receiver r, V value) {
    if (value == null) {
        // top and top is also the default value.
        return;
    }
    InitializationAnnotatedTypeFactory<?, ?, ?, ?> atypeFactory = (InitializationAnnotatedTypeFactory<?, ?, ?, ?>) analysis.getTypeFactory();
    QualifierHierarchy qualifierHierarchy = atypeFactory.getQualifierHierarchy();
    AnnotationMirror invariantAnno = atypeFactory.getFieldInvariantAnnotation();
    // Remember fields that have the 'invariant' annotation in the store.
    if (r instanceof FieldAccess) {
        FieldAccess fieldAccess = (FieldAccess) r;
        if (!fieldValues.containsKey(r)) {
            Set<AnnotationMirror> declaredAnnos = atypeFactory.getAnnotatedType(fieldAccess.getField()).getAnnotations();
            if (AnnotationUtils.containsSame(declaredAnnos, invariantAnno)) {
                if (!invariantFields.containsKey(fieldAccess)) {
                    invariantFields.put(fieldAccess, analysis.createSingleAnnotationValue(invariantAnno, r.getType()));
                }
            }
        }
    }
    super.insertValue(r, value);
    for (AnnotationMirror a : value.getAnnotations()) {
        if (qualifierHierarchy.isSubtype(a, invariantAnno)) {
            if (r instanceof FieldAccess) {
                FieldAccess fa = (FieldAccess) r;
                if (fa.getReceiver() instanceof ThisReference || fa.getReceiver() instanceof ClassName) {
                    addInitializedField(fa.getField());
                }
            }
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy) ClassName(org.checkerframework.dataflow.analysis.FlowExpressions.ClassName) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) ThisReference(org.checkerframework.dataflow.analysis.FlowExpressions.ThisReference)

Example 12 with QualifierHierarchy

use of org.checkerframework.framework.type.QualifierHierarchy in project checker-framework by typetools.

the class CFAbstractAnalysis method createSingleAnnotationValue.

/**
 * Returns an abstract value containing an annotated type with the annotation {@code anno}, and
 * 'top' for all other hierarchies. The underlying type is {@link Object}.
 */
public V createSingleAnnotationValue(AnnotationMirror anno, TypeMirror underlyingType) {
    QualifierHierarchy hierarchy = getTypeFactory().getQualifierHierarchy();
    Set<AnnotationMirror> annos = AnnotationUtils.createAnnotationSet();
    annos.addAll(hierarchy.getTopAnnotations());
    AnnotationMirror f = hierarchy.findAnnotationInSameHierarchy(annos, anno);
    annos.remove(f);
    annos.add(anno);
    return createAbstractValue(annos, underlyingType);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy)

Example 13 with QualifierHierarchy

use of org.checkerframework.framework.type.QualifierHierarchy in project checker-framework by typetools.

the class LockStore method changeLockAnnoToTop.

/**
 * Makes a new CFValue with the same annotations as currentValue except that the annotation in
 * the LockPossiblyHeld hierarchy is set to LockPossiblyHeld. If currentValue is null, then a
 * new value is created where the annotation set is LockPossiblyHeld and GuardedByUnknown
 */
private CFValue changeLockAnnoToTop(Receiver r, CFValue currentValue) {
    if (currentValue == null) {
        Set<AnnotationMirror> set = AnnotationUtils.createAnnotationSet();
        set.add(atypeFactory.GUARDEDBYUNKNOWN);
        set.add(atypeFactory.LOCKPOSSIBLYHELD);
        return analysis.createAbstractValue(set, r.getType());
    }
    QualifierHierarchy hierarchy = atypeFactory.getQualifierHierarchy();
    Set<AnnotationMirror> currentSet = currentValue.getAnnotations();
    AnnotationMirror gb = hierarchy.findAnnotationInHierarchy(currentSet, atypeFactory.GUARDEDBYUNKNOWN);
    Set<AnnotationMirror> newSet = AnnotationUtils.createAnnotationSet();
    newSet.add(atypeFactory.LOCKPOSSIBLYHELD);
    if (gb != null) {
        newSet.add(gb);
    }
    return analysis.createAbstractValue(newSet, currentValue.getUnderlyingType());
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy)

Example 14 with QualifierHierarchy

use of org.checkerframework.framework.type.QualifierHierarchy in project checker-framework by typetools.

the class LockVisitor method isLockHeld.

private boolean isLockHeld(Receiver lock, LockStore store) {
    if (store == null) {
        return false;
    }
    CFAbstractValue<?> value = store.getValue(lock);
    if (value == null) {
        return false;
    }
    Set<AnnotationMirror> annos = value.getAnnotations();
    QualifierHierarchy hierarchy = atypeFactory.getQualifierHierarchy();
    AnnotationMirror lockAnno = hierarchy.findAnnotationInSameHierarchy(annos, atypeFactory.LOCKHELD);
    return lockAnno != null && AnnotationUtils.areSameByClass(lockAnno, LockHeld.class);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) EnsuresLockHeld(org.checkerframework.checker.lock.qual.EnsuresLockHeld) LockHeld(org.checkerframework.checker.lock.qual.LockHeld) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy)

Example 15 with QualifierHierarchy

use of org.checkerframework.framework.type.QualifierHierarchy in project checker-framework by typetools.

the class FenumVisitor method visitBinary.

@Override
public Void visitBinary(BinaryTree node, Void p) {
    if (!TreeUtils.isStringConcatenation(node)) {
        // TODO: ignore string concatenations
        // The Fenum Checker is only concerned with primitive types, so just check that
        // the primary annotations are equivalent.
        AnnotatedTypeMirror lhsAtm = atypeFactory.getAnnotatedType(node.getLeftOperand());
        AnnotatedTypeMirror rhsAtm = atypeFactory.getAnnotatedType(node.getRightOperand());
        Set<AnnotationMirror> lhs = lhsAtm.getEffectiveAnnotations();
        Set<AnnotationMirror> rhs = rhsAtm.getEffectiveAnnotations();
        QualifierHierarchy qualHierarchy = atypeFactory.getQualifierHierarchy();
        if (!(qualHierarchy.isSubtype(lhs, rhs) || qualHierarchy.isSubtype(rhs, lhs))) {
            checker.report(Result.failure("binary.type.incompatible", lhsAtm, rhsAtm), node);
        }
    }
    return super.visitBinary(node, p);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) QualifierHierarchy(org.checkerframework.framework.type.QualifierHierarchy) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Aggregations

QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)25 AnnotationMirror (javax.lang.model.element.AnnotationMirror)22 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)9 AnnotationMirrorSet (org.checkerframework.framework.util.AnnotationMirrorSet)6 ArrayList (java.util.ArrayList)4 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)4 TypeVariable (javax.lang.model.type.TypeVariable)3 Elements (javax.lang.model.util.Elements)3 Types (javax.lang.model.util.Types)3 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)3 TypeUseLocation (org.checkerframework.framework.qual.TypeUseLocation)2 AnnotationMirrorMap (org.checkerframework.framework.util.AnnotationMirrorMap)2 InferredType (org.checkerframework.framework.util.typeinference.solver.InferredValue.InferredType)2 AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)2 MethodTree (com.sun.source.tree.MethodTree)1 Entry (java.util.Map.Entry)1 TypeMirror (javax.lang.model.type.TypeMirror)1 A (lubglb.quals.A)1 B (lubglb.quals.B)1 C (lubglb.quals.C)1