Search in sources :

Example 1 with ConditionalPostcondition

use of org.checkerframework.framework.util.ContractsUtils.ConditionalPostcondition 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 2 with ConditionalPostcondition

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

the class CFAbstractTransfer method processPostconditionsAndConditionalPostconditions.

private void processPostconditionsAndConditionalPostconditions(MethodInvocationNode n, Tree tree, S thenStore, S elseStore, Set<? extends Contract> postconditions) {
    FlowExpressionContext flowExprContext = null;
    for (Contract p : postconditions) {
        String expression = p.expression;
        AnnotationMirror anno = p.annotation;
        if (flowExprContext == null) {
            flowExprContext = FlowExpressionContext.buildContextForMethodUse(n, analysis.checker.getContext());
        }
        TreePath localScope = analysis.atypeFactory.getPath(tree);
        anno = standardizeAnnotationFromContract(anno, flowExprContext, localScope);
        try {
            FlowExpressions.Receiver r = FlowExpressionParseUtil.parse(expression, flowExprContext, localScope, false);
            if (p.kind == Contract.Kind.CONDITIONALPOSTCONDTION) {
                if (((ConditionalPostcondition) p).annoResult) {
                    thenStore.insertValue(r, anno);
                } else {
                    elseStore.insertValue(r, anno);
                }
            } else {
                thenStore.insertValue(r, anno);
            }
        } catch (FlowExpressionParseException e) {
            Result result;
            if (e.isFlowParseError()) {
                Object[] args = new Object[e.args.length + 1];
                args[0] = ElementUtils.getVerboseName(TreeUtils.elementFromUse(n.getTree()));
                System.arraycopy(e.args, 0, args, 1, e.args.length);
                result = Result.failure("flowexpr.parse.error.postcondition", args);
            } else {
                result = e.getResult();
            }
            // report errors here
            analysis.checker.report(result, tree);
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TreePath(com.sun.source.util.TreePath) FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) FlowExpressionParseException(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionParseException) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) ConditionalPostcondition(org.checkerframework.framework.util.ContractsUtils.ConditionalPostcondition) Contract(org.checkerframework.framework.util.ContractsUtils.Contract) TransferResult(org.checkerframework.dataflow.analysis.TransferResult) Result(org.checkerframework.framework.source.Result) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult)

Aggregations

ConditionalPostcondition (org.checkerframework.framework.util.ContractsUtils.ConditionalPostcondition)2 TreePath (com.sun.source.util.TreePath)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)1 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)1 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)1 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)1 TransferResult (org.checkerframework.dataflow.analysis.TransferResult)1 Result (org.checkerframework.framework.source.Result)1 ContractsUtils (org.checkerframework.framework.util.ContractsUtils)1 Contract (org.checkerframework.framework.util.ContractsUtils.Contract)1 FlowExpressionContext (org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext)1 FlowExpressionParseException (org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionParseException)1