Search in sources :

Example 1 with CFAnalysis

use of org.checkerframework.framework.flow.CFAnalysis in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method createFlowAnalysis.

/**
 * Returns the appropriate flow analysis class that is used for the
 * org.checkerframework.dataflow analysis.
 *
 * <p>This implementation uses the checker naming convention to create the appropriate analysis.
 * If no transfer function is found, it returns an instance of {@link CFAnalysis}.
 *
 * <p>Subclasses have to override this method to create the appropriate analysis if they do not
 * follow the checker naming convention.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected FlowAnalysis createFlowAnalysis(List<Pair<VariableElement, Value>> fieldValues) {
    // Try to reflectively load the visitor.
    Class<?> checkerClass = checker.getClass();
    while (checkerClass != BaseTypeChecker.class) {
        final String classToLoad = checkerClass.getName().replace("Checker", "Analysis").replace("Subchecker", "Analysis");
        FlowAnalysis result = BaseTypeChecker.invokeConstructorFor(classToLoad, new Class<?>[] { BaseTypeChecker.class, this.getClass(), List.class }, new Object[] { checker, this, fieldValues });
        if (result != null) {
            return result;
        }
        checkerClass = checkerClass.getSuperclass();
    }
    // If an analysis couldn't be loaded reflectively, return the
    // default.
    List<Pair<VariableElement, CFValue>> tmp = new ArrayList<>();
    for (Pair<VariableElement, Value> fieldVal : fieldValues) {
        assert fieldVal.second instanceof CFValue;
        tmp.add(Pair.of(fieldVal.first, (CFValue) fieldVal.second));
    }
    return (FlowAnalysis) new CFAnalysis(checker, (GenericAnnotatedTypeFactory) this, tmp);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) CFAnalysis(org.checkerframework.framework.flow.CFAnalysis) ArrayList(java.util.ArrayList) CFAbstractValue(org.checkerframework.framework.flow.CFAbstractValue) CFValue(org.checkerframework.framework.flow.CFValue) VariableElement(javax.lang.model.element.VariableElement) Pair(org.checkerframework.javacutil.Pair)

Aggregations

ArrayList (java.util.ArrayList)1 VariableElement (javax.lang.model.element.VariableElement)1 CFAbstractValue (org.checkerframework.framework.flow.CFAbstractValue)1 CFAnalysis (org.checkerframework.framework.flow.CFAnalysis)1 CFValue (org.checkerframework.framework.flow.CFValue)1 Pair (org.checkerframework.javacutil.Pair)1