use of org.checkerframework.framework.util.Contract.Postcondition 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.Contract.Postcondition in project checker-framework by typetools.
the class BaseTypeVisitor method checkContractsAtMethodDeclaration.
/**
* Check the contracts written on a method declaration. Ensures that the postconditions hold on
* exit, and that the contracts are well-formed.
*
* @param methodTree the method declaration
* @param methodElement the method element
* @param formalParamNames the formal parameter names
* @param abstractMethod whether the method is abstract
*/
private void checkContractsAtMethodDeclaration(MethodTree methodTree, ExecutableElement methodElement, List<String> formalParamNames, boolean abstractMethod) {
Set<Contract> contracts = atypeFactory.getContractsFromMethod().getContracts(methodElement);
if (contracts.isEmpty()) {
return;
}
StringToJavaExpression stringToJavaExpr = stringExpr -> StringToJavaExpression.atMethodBody(stringExpr, methodTree, checker);
for (Contract contract : contracts) {
String expressionString = contract.expressionString;
AnnotationMirror annotation = contract.viewpointAdaptDependentTypeAnnotation(atypeFactory, stringToJavaExpr, methodTree);
JavaExpression exprJe;
try {
exprJe = StringToJavaExpression.atMethodBody(expressionString, methodTree, checker);
} catch (JavaExpressionParseException e) {
DiagMessage diagMessage = e.getDiagMessage();
if (diagMessage.getMessageKey().equals("flowexpr.parse.error")) {
String s = String.format("'%s' in the %s %s on the declaration of method '%s': ", expressionString, contract.kind.errorKey, contract.contractAnnotation.getAnnotationType().asElement().getSimpleName(), methodTree.getName().toString());
checker.reportError(methodTree, "flowexpr.parse.error", s + diagMessage.getArgs()[0]);
} else {
checker.report(methodTree, e.getDiagMessage());
}
continue;
}
if (!CFAbstractStore.canInsertJavaExpression(exprJe)) {
checker.reportError(methodTree, "flowexpr.parse.error", expressionString);
continue;
}
if (!abstractMethod && contract.kind != Contract.Kind.PRECONDITION) {
switch(contract.kind) {
case POSTCONDITION:
checkPostcondition(methodTree, annotation, exprJe);
break;
case CONDITIONALPOSTCONDITION:
checkConditionalPostcondition(methodTree, annotation, exprJe, ((ConditionalPostcondition) contract).resultValue);
break;
default:
throw new BugInCF("Impossible: " + contract.kind);
}
}
if (formalParamNames != null && formalParamNames.contains(expressionString)) {
String locationOfExpression = contract.kind.errorKey + " " + contract.contractAnnotation.getAnnotationType().asElement().getSimpleName() + " on the declaration";
checker.reportWarning(methodTree, "expression.parameter.name.shadows.field", locationOfExpression, methodTree.getName().toString(), expressionString, expressionString, formalParamNames.indexOf(expressionString) + 1);
}
checkParametersAreEffectivelyFinal(methodTree, exprJe);
}
}
Aggregations