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());
}
}
}
}
}
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);
}
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());
}
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);
}
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);
}
Aggregations