Search in sources :

Example 1 with ValueAnnotatedTypeFactory

use of org.checkerframework.common.value.ValueAnnotatedTypeFactory in project checker-framework by typetools.

the class MethodSignature method getMethodNamesFromStringArg.

/**
 * Returns the string values for the argument passed. The String Values are estimated using the
 * Value Checker.
 *
 * @param arg ExpressionTree whose string values are sought
 * @return string values of arg or the empty list if no values were found
 */
private List<String> getMethodNamesFromStringArg(ExpressionTree arg) {
    List<String> methodNames = new ArrayList<>();
    ValueAnnotatedTypeFactory valueATF = getTypeFactoryOfSubchecker(ValueChecker.class);
    AnnotatedTypeMirror valueAnno = valueATF.getAnnotatedType(arg);
    AnnotationMirror annotation = valueAnno.getAnnotation(StringVal.class);
    if (annotation != null) {
        methodNames = AnnotationUtils.getElementValueArray(annotation, "value", String.class, true);
    }
    return methodNames;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayList(java.util.ArrayList) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) ValueAnnotatedTypeFactory(org.checkerframework.common.value.ValueAnnotatedTypeFactory)

Example 2 with ValueAnnotatedTypeFactory

use of org.checkerframework.common.value.ValueAnnotatedTypeFactory 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

ValueAnnotatedTypeFactory (org.checkerframework.common.value.ValueAnnotatedTypeFactory)2 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 SameLenAnnotatedTypeFactory (org.checkerframework.checker.index.samelen.SameLenAnnotatedTypeFactory)1