Search in sources :

Example 1 with SameLenAnnotatedTypeFactory

use of org.checkerframework.checker.index.samelen.SameLenAnnotatedTypeFactory in project checker-framework by typetools.

the class UpperBoundVisitor method relaxedCommonAssignmentCheck.

/**
 * Implements the actual check for the relaxed common assignment check. For what is permitted,
 * see {@link #relaxedCommonAssignment}.
 */
private boolean relaxedCommonAssignmentCheck(LessThanLengthOf varLtlQual, ExpressionTree valueExp) {
    AnnotatedTypeMirror expType = atypeFactory.getAnnotatedType(valueExp);
    UBQualifier expQual = UBQualifier.createUBQualifier(expType, atypeFactory.UNKNOWN);
    UBQualifier lessThanQual = atypeFactory.fromLessThan(valueExp, getCurrentPath());
    if (lessThanQual != null) {
        expQual = expQual.glb(lessThanQual);
    }
    UBQualifier lessThanOrEqualQual = atypeFactory.fromLessThanOrEqual(valueExp, getCurrentPath());
    if (lessThanOrEqualQual != null) {
        expQual = expQual.glb(lessThanOrEqualQual);
    }
    if (expQual.isSubtype(varLtlQual)) {
        return true;
    }
    Long value = IndexUtil.getMaxValue(valueExp, atypeFactory.getValueAnnotatedTypeFactory());
    if (value == null && !expQual.isLessThanLengthQualifier()) {
        return false;
    }
    SameLenAnnotatedTypeFactory sameLenFactory = atypeFactory.getSameLenAnnotatedTypeFactory();
    ValueAnnotatedTypeFactory valueAnnotatedTypeFactory = atypeFactory.getValueAnnotatedTypeFactory();
    checkloop: for (String sequenceName : varLtlQual.getSequences()) {
        List<String> sameLenSequences = sameLenFactory.getSameLensFromString(sequenceName, valueExp, getCurrentPath());
        if (testSameLen(expQual, varLtlQual, sameLenSequences, sequenceName)) {
            continue;
        }
        int minlen = valueAnnotatedTypeFactory.getMinLenFromString(sequenceName, valueExp, getCurrentPath());
        if (testMinLen(value, minlen, sequenceName, varLtlQual)) {
            continue;
        }
        for (String sequence : sameLenSequences) {
            int minlenSL = valueAnnotatedTypeFactory.getMinLenFromString(sequence, valueExp, getCurrentPath());
            if (testMinLen(value, minlenSL, sequenceName, varLtlQual)) {
                continue checkloop;
            }
        }
        return false;
    }
    return true;
}
Also used : SameLenAnnotatedTypeFactory(org.checkerframework.checker.index.samelen.SameLenAnnotatedTypeFactory) List(java.util.List) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) ValueAnnotatedTypeFactory(org.checkerframework.common.value.ValueAnnotatedTypeFactory)

Aggregations

List (java.util.List)1 SameLenAnnotatedTypeFactory (org.checkerframework.checker.index.samelen.SameLenAnnotatedTypeFactory)1 ValueAnnotatedTypeFactory (org.checkerframework.common.value.ValueAnnotatedTypeFactory)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1