use of org.checkerframework.framework.util.ContractsFromMethod in project checker-framework by typetools.
the class CFAbstractTransfer method addInformationFromPreconditions.
/**
* Add the information from all the preconditions of a method to the initial store in the method
* body.
*
* @param initialStore the initial store for the method body
* @param factory the type factory
* @param methodAst the AST for a method declaration
* @param methodDeclTree the declaration of the method; is a field of {@code methodAst}
* @param methodElement the element for the method
*/
protected void addInformationFromPreconditions(S initialStore, AnnotatedTypeFactory factory, CFGMethod methodAst, MethodTree methodDeclTree, ExecutableElement methodElement) {
ContractsFromMethod contractsUtils = analysis.atypeFactory.getContractsFromMethod();
Set<Precondition> preconditions = contractsUtils.getPreconditions(methodElement);
StringToJavaExpression stringToJavaExpr = stringExpr -> StringToJavaExpression.atMethodBody(stringExpr, methodDeclTree, analysis.checker);
for (Precondition p : preconditions) {
String stringExpr = p.expressionString;
AnnotationMirror annotation = p.viewpointAdaptDependentTypeAnnotation(analysis.atypeFactory, stringToJavaExpr, /*errorTree=*/
null);
JavaExpression exprJe;
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)
exprJe = StringToJavaExpression.atMethodBody(stringExpr, methodDeclTree, analysis.checker);
} catch (JavaExpressionParseException e) {
// Errors are reported by BaseTypeVisitor.checkContractsAtMethodDeclaration().
continue;
}
initialStore.insertValuePermitNondeterministic(exprJe, annotation);
}
}
use of org.checkerframework.framework.util.ContractsFromMethod in project checker-framework by typetools.
the class CFAbstractTransfer method processPostconditions.
/**
* Add information from the postconditions of a method to the store after an invocation.
*
* @param invocationNode a method call
* @param store a store; is side-effected by this method
* @param methodElement the method being called
* @param invocationTree the tree for the method call
*/
protected void processPostconditions(MethodInvocationNode invocationNode, S store, ExecutableElement methodElement, Tree invocationTree) {
ContractsFromMethod contractsUtils = analysis.atypeFactory.getContractsFromMethod();
Set<Postcondition> postconditions = contractsUtils.getPostconditions(methodElement);
processPostconditionsAndConditionalPostconditions(invocationNode, invocationTree, store, null, postconditions);
}
use of org.checkerframework.framework.util.ContractsFromMethod in project checker-framework by typetools.
the class CFAbstractTransfer method processConditionalPostconditions.
/**
* Add information from the conditional postconditions of a method to the stores after an
* invocation.
*
* @param invocationNode a method call
* @param methodElement the method being called
* @param invocationTree the tree for the method call
* @param thenStore the "then" store; is side-effected by this method
* @param elseStore the "else" store; is side-effected by this method
*/
protected void processConditionalPostconditions(MethodInvocationNode invocationNode, ExecutableElement methodElement, Tree invocationTree, S thenStore, S elseStore) {
ContractsFromMethod contractsUtils = analysis.atypeFactory.getContractsFromMethod();
Set<ConditionalPostcondition> conditionalPostconditions = contractsUtils.getConditionalPostconditions(methodElement);
processPostconditionsAndConditionalPostconditions(invocationNode, invocationTree, thenStore, elseStore, conditionalPostconditions);
}
Aggregations