use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class ValueTransfer method processConditionalPostconditions.
@Override
protected void processConditionalPostconditions(MethodInvocationNode n, ExecutableElement methodElement, Tree tree, CFStore thenStore, CFStore elseStore) {
// For String.startsWith(String) and String.endsWith(String), refine the minimum length
// of the receiver to the minimum length of the argument.
ValueMethodIdentifier methodIdentifier = atypeFactory.getMethodIdentifier();
if (methodIdentifier.isStartsWithMethod(methodElement) || methodIdentifier.isEndsWithMethod(methodElement)) {
Node argumentNode = n.getArgument(0);
AnnotationMirror argumentAnno = getArrayOrStringAnnotation(argumentNode);
int minLength = atypeFactory.getMinLenValue(argumentAnno);
// Update the annotation of the receiver
if (minLength != 0) {
JavaExpression receiver = JavaExpression.fromNode(n.getTarget().getReceiver());
AnnotationMirror minLenAnno = atypeFactory.createArrayLenRangeAnnotation(minLength, Integer.MAX_VALUE);
thenStore.insertValuePermitNondeterministic(receiver, minLenAnno);
}
}
super.processConditionalPostconditions(n, methodElement, tree, thenStore, elseStore);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class CFAbstractTransfer method processPostconditionsAndConditionalPostconditions.
/**
* Add information from the postconditions and conditional postconditions of a method to the
* stores after an invocation.
*
* @param invocationNode a method call
* @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
* @param postconditions the postconditions
*/
private void processPostconditionsAndConditionalPostconditions(MethodInvocationNode invocationNode, Tree invocationTree, S thenStore, S elseStore, Set<? extends Contract> postconditions) {
StringToJavaExpression stringToJavaExpr = stringExpr -> StringToJavaExpression.atMethodInvocation(stringExpr, invocationNode, analysis.checker);
for (Contract p : postconditions) {
// Viewpoint-adapt to the method use (the call site).
AnnotationMirror anno = p.viewpointAdaptDependentTypeAnnotation(analysis.atypeFactory, stringToJavaExpr, /*errorTree=*/
null);
String expressionString = p.expressionString;
try {
JavaExpression je = stringToJavaExpr.toJavaExpression(expressionString);
// are removed from the store before this method is called.
if (p.kind == Contract.Kind.CONDITIONALPOSTCONDITION) {
if (((ConditionalPostcondition) p).resultValue) {
thenStore.insertOrRefinePermitNondeterministic(je, anno);
} else {
elseStore.insertOrRefinePermitNondeterministic(je, anno);
}
} else {
thenStore.insertOrRefinePermitNondeterministic(je, anno);
}
} catch (JavaExpressionParseException e) {
// report errors here
if (e.isFlowParseError()) {
Object[] args = new Object[e.args.length + 1];
args[0] = ElementUtils.getSimpleSignature(TreeUtils.elementFromUse(invocationNode.getTree()));
System.arraycopy(e.args, 0, args, 1, e.args.length);
analysis.checker.reportError(invocationTree, "flowexpr.parse.error.postcondition", args);
} else {
analysis.checker.report(invocationTree, e.getDiagMessage());
}
}
}
}
Aggregations