Search in sources :

Example 1 with ContractsUtils

use of org.checkerframework.framework.util.ContractsUtils in project checker-framework by typetools.

the class CFAbstractTransfer method processPostconditions.

/**
 * Add information based on all postconditions of method {@code n} with tree {@code tree} and
 * element {@code method} to the store {@code store}.
 */
protected void processPostconditions(MethodInvocationNode n, S store, ExecutableElement methodElement, Tree tree) {
    ContractsUtils contracts = ContractsUtils.getInstance(analysis.atypeFactory);
    Set<Postcondition> postconditions = contracts.getPostconditions(methodElement);
    processPostconditionsAndConditionalPostconditions(n, tree, store, null, postconditions);
}
Also used : ContractsUtils(org.checkerframework.framework.util.ContractsUtils) ConditionalPostcondition(org.checkerframework.framework.util.ContractsUtils.ConditionalPostcondition) Postcondition(org.checkerframework.framework.util.ContractsUtils.Postcondition)

Example 2 with ContractsUtils

use of org.checkerframework.framework.util.ContractsUtils in project checker-framework by typetools.

the class CFAbstractTransfer method processConditionalPostconditions.

/**
 * Add information based on all conditional postconditions of method {@code n} with tree {@code
 * tree} and element {@code method} to the appropriate store.
 */
protected void processConditionalPostconditions(MethodInvocationNode n, ExecutableElement methodElement, Tree tree, S thenStore, S elseStore) {
    ContractsUtils contracts = ContractsUtils.getInstance(analysis.atypeFactory);
    Set<ConditionalPostcondition> conditionalPostconditions = contracts.getConditionalPostconditions(methodElement);
    processPostconditionsAndConditionalPostconditions(n, tree, thenStore, elseStore, conditionalPostconditions);
}
Also used : ContractsUtils(org.checkerframework.framework.util.ContractsUtils) ConditionalPostcondition(org.checkerframework.framework.util.ContractsUtils.ConditionalPostcondition)

Example 3 with ContractsUtils

use of org.checkerframework.framework.util.ContractsUtils in project checker-framework by typetools.

the class CFAbstractTransfer method addInformationFromPreconditions.

/**
 * Add the information from all the preconditions of the method {@code method} with
 * corresponding tree {@code methodTree} to the store {@code info}.
 */
protected void addInformationFromPreconditions(S info, AnnotatedTypeFactory factory, CFGMethod method, MethodTree methodTree, ExecutableElement methodElement) {
    ContractsUtils contracts = ContractsUtils.getInstance(analysis.atypeFactory);
    FlowExpressionContext flowExprContext = null;
    Set<Precondition> preconditions = contracts.getPreconditions(methodElement);
    for (Precondition p : preconditions) {
        String expression = p.expression;
        AnnotationMirror annotation = p.annotation;
        if (flowExprContext == null) {
            flowExprContext = FlowExpressionContext.buildContextForMethodDeclaration(methodTree, method.getClassTree(), analysis.checker.getContext());
        }
        TreePath localScope = analysis.atypeFactory.getPath(methodTree);
        annotation = standardizeAnnotationFromContract(annotation, flowExprContext, localScope);
        try {
            // TODO: currently, these expressions are parsed at the
            // declaration (i.e. here) and for every use. this could
            // be optimized to store the result the first time.
            // (same for other annotations)
            FlowExpressions.Receiver expr = FlowExpressionParseUtil.parse(expression, flowExprContext, localScope, false);
            info.insertValue(expr, annotation);
        } catch (FlowExpressionParseException e) {
        // Errors are reported by BaseTypeVisitor.checkContractsAtMethodDeclaration()
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TreePath(com.sun.source.util.TreePath) FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) Precondition(org.checkerframework.framework.util.ContractsUtils.Precondition) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) FlowExpressionParseException(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionParseException) ContractsUtils(org.checkerframework.framework.util.ContractsUtils) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Aggregations

ContractsUtils (org.checkerframework.framework.util.ContractsUtils)3 ConditionalPostcondition (org.checkerframework.framework.util.ContractsUtils.ConditionalPostcondition)2 TreePath (com.sun.source.util.TreePath)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)1 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)1 Postcondition (org.checkerframework.framework.util.ContractsUtils.Postcondition)1 Precondition (org.checkerframework.framework.util.ContractsUtils.Precondition)1 FlowExpressionContext (org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext)1 FlowExpressionParseException (org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionParseException)1