use of org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext 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);
}
}
}
use of org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext in project checker-framework by typetools.
the class LockAnnotatedTypeFactory method createDependentTypesHelper.
@Override
protected DependentTypesHelper createDependentTypesHelper() {
return new DependentTypesHelper(this) {
@Override
protected void reportErrors(Tree errorTree, List<DependentTypesError> errors) {
// If the error message is NOT_EFFECTIVELY_FINAL, then report lock.expression.not
// .final instead of an expression.unparsable.type.invalid error.
List<DependentTypesError> superErrors = new ArrayList<>();
for (DependentTypesError error : errors) {
if (error.error.equals(NOT_EFFECTIVELY_FINAL)) {
checker.report(Result.failure("lock.expression.not.final", error.expression), errorTree);
} else {
superErrors.add(error);
}
}
super.reportErrors(errorTree, superErrors);
}
@Override
protected String standardizeString(String expression, FlowExpressionContext context, TreePath localScope, boolean useLocalScope) {
if (DependentTypesError.isExpressionError(expression)) {
return expression;
}
// Adds logic to parse <self> expression, which only the Lock Checker uses.
if (LockVisitor.selfReceiverPattern.matcher(expression).matches()) {
return expression;
}
try {
FlowExpressions.Receiver result = FlowExpressionParseUtil.parse(expression, context, localScope, useLocalScope);
if (result == null) {
return new DependentTypesError(expression, " ").toString();
}
if (!isExpressionEffectivelyFinal(result)) {
// NOT_EFFECTIVELY_FINAL error string.
return new DependentTypesError(expression, NOT_EFFECTIVELY_FINAL).toString();
}
return result.toString();
} catch (FlowExpressionParseUtil.FlowExpressionParseException e) {
return new DependentTypesError(expression, e).toString();
}
}
};
}
use of org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext in project checker-framework by typetools.
the class DependentTypesHelper method standardizeNewClassTree.
public void standardizeNewClassTree(NewClassTree tree, AnnotatedDeclaredType type) {
if (!hasDependentType(type)) {
return;
}
TreePath path = factory.getPath(tree);
FlowExpressions.Receiver r = FlowExpressions.internalReprOfImplicitReceiver(TreeUtils.elementFromUse(tree));
FlowExpressionContext context = new FlowExpressionContext(r, FlowExpressions.getParametersOfEnclosingMethod(factory, path), factory.getContext());
standardizeUseLocals(context, path, type);
}
use of org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext in project checker-framework by typetools.
the class DependentTypesHelper method standardizeExpression.
public void standardizeExpression(ExpressionTree tree, AnnotatedTypeMirror annotatedType) {
if (!hasDependentType(annotatedType)) {
return;
}
TreePath path = factory.getPath(tree);
if (path == null) {
return;
}
Tree enclosingClass = TreeUtils.enclosingClass(path);
if (enclosingClass == null) {
return;
}
TypeMirror enclosingType = TreeUtils.typeOf(enclosingClass);
FlowExpressions.Receiver receiver = FlowExpressions.internalReprOfPseudoReceiver(path, enclosingType);
FlowExpressionContext localContext = new FlowExpressionContext(receiver, FlowExpressions.getParametersOfEnclosingMethod(factory, path), factory.getContext());
standardizeUseLocals(localContext, path, annotatedType);
}
use of org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext in project checker-framework by typetools.
the class DependentTypesHelper method standardizeFieldAccess.
public void standardizeFieldAccess(MemberSelectTree node, AnnotatedTypeMirror type) {
if (!hasDependentType(type)) {
return;
}
if (TreeUtils.isClassLiteral(node)) {
return;
}
Element ele = TreeUtils.elementFromUse(node);
if (ele.getKind() != ElementKind.FIELD) {
return;
}
FlowExpressions.Receiver receiver = FlowExpressions.internalReprOf(factory, node.getExpression());
FlowExpressionContext context = new FlowExpressionContext(receiver, null, factory.getContext());
standardizeDoNotUseLocals(context, factory.getPath(node), type);
}
Aggregations