use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class StringToJavaExpression method atPath.
/**
* Parses a string as if it were written at {@code localVarPath}.
*
* @param expression a Java expression to parse
* @param localVarPath location at which {@code expression} is parsed
* @param checker checker used to get the {@link
* javax.annotation.processing.ProcessingEnvironment} and current {@link
* com.sun.source.tree.CompilationUnitTree}
* @return a {@code JavaExpression} for {@code expression}
* @throws JavaExpressionParseException if {@code expression} cannot be parsed
*/
static JavaExpression atPath(String expression, TreePath localVarPath, SourceChecker checker) throws JavaExpressionParseException {
TypeMirror enclosingType = TreeUtils.typeOf(TreePathUtil.enclosingClass(localVarPath));
ThisReference thisReference = TreePathUtil.isTreeInStaticScope(localVarPath) ? null : new ThisReference(enclosingType);
MethodTree methodTree = TreePathUtil.enclosingMethod(localVarPath);
if (methodTree == null) {
return JavaExpressionParseUtil.parse(expression, enclosingType, thisReference, null, localVarPath, checker.getPathToCompilationUnit(), checker.getProcessingEnvironment());
}
ExecutableElement methodEle = TreeUtils.elementFromDeclaration(methodTree);
List<FormalParameter> parameters = JavaExpression.getFormalParameters(methodEle);
JavaExpression javaExpr = JavaExpressionParseUtil.parse(expression, enclosingType, thisReference, parameters, localVarPath, checker.getPathToCompilationUnit(), checker.getProcessingEnvironment());
List<JavaExpression> paramsAsLocals = JavaExpression.getParametersAsLocalVariables(methodEle);
return ViewpointAdaptJavaExpression.viewpointAdapt(javaExpr, paramsAsLocals);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class StringToJavaExpression method atConstructorInvocation.
/**
* Parses a string as if it were written at the declaration of the invoked constructor and then
* viewpoint-adapts the result to the call site.
*
* @param expression a Java expression to parse
* @param newClassTree constructor invocation
* @param checker checker used to get the {@link
* javax.annotation.processing.ProcessingEnvironment} and current {@link
* com.sun.source.tree.CompilationUnitTree}
* @return a {@code JavaExpression} for {@code expression}
* @throws JavaExpressionParseException if {@code expression} cannot be parsed
*/
static JavaExpression atConstructorInvocation(String expression, NewClassTree newClassTree, SourceChecker checker) throws JavaExpressionParseException {
ExecutableElement ee = TreeUtils.elementFromUse(newClassTree);
JavaExpression javaExpr = StringToJavaExpression.atMethodDecl(expression, ee, checker);
return javaExpr.atConstructorInvocation(newClassTree);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class StringToJavaExpression method atMethodInvocation.
/**
* Parses a string as if it were written at the declaration of the invoked method and then
* viewpoint-adapts the result to the call site.
*
* @param expression a Java expression to parse
* @param methodInvocationTree method invocation tree
* @param checker checker used to get the {@link
* javax.annotation.processing.ProcessingEnvironment} and current {@link
* com.sun.source.tree.CompilationUnitTree}
* @return a {@code JavaExpression} for {@code expression}
* @throws JavaExpressionParseException if {@code expression} cannot be parsed
*/
static JavaExpression atMethodInvocation(String expression, MethodInvocationTree methodInvocationTree, SourceChecker checker) throws JavaExpressionParseException {
ExecutableElement ee = TreeUtils.elementFromUse(methodInvocationTree);
JavaExpression javaExpr = StringToJavaExpression.atMethodDecl(expression, ee, checker);
return javaExpr.atMethodInvocation(methodInvocationTree);
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class LowerBoundTransfer method notEqualToValue.
/**
* Refines GTEN1 to NN if it is not equal to -1, and NN to Pos if it is not equal to 0. Implements
* case 7.
*
* @param mLiteral a potential literal
* @param otherNode the node on the other side of the ==/!=
* @param otherAnno the annotation of the other side of the ==/!=
*/
private void notEqualToValue(Node mLiteral, Node otherNode, AnnotationMirror otherAnno, CFStore store) {
Long integerLiteral = ValueCheckerUtils.getExactValue(mLiteral.getTree(), aTypeFactory.getValueAnnotatedTypeFactory());
if (integerLiteral == null) {
return;
}
long intLiteral = integerLiteral.longValue();
if (intLiteral == 0) {
if (aTypeFactory.areSameByClass(otherAnno, NonNegative.class)) {
List<Node> internals = splitAssignments(otherNode);
for (Node internal : internals) {
JavaExpression je = JavaExpression.fromNode(internal);
store.insertValue(je, POS);
}
}
} else if (intLiteral == -1) {
if (aTypeFactory.areSameByClass(otherAnno, GTENegativeOne.class)) {
List<Node> internals = splitAssignments(otherNode);
for (Node internal : internals) {
JavaExpression je = JavaExpression.fromNode(internal);
store.insertValue(je, NN);
}
}
}
}
use of org.checkerframework.dataflow.expression.JavaExpression in project checker-framework by typetools.
the class LowerBoundTransfer method addInformationFromPreconditions.
/**
* Adds a default NonNegative annotation to every character. Implements case 33.
*/
@Override
protected void addInformationFromPreconditions(CFStore info, AnnotatedTypeFactory factory, UnderlyingAST.CFGMethod method, MethodTree methodTree, ExecutableElement methodElement) {
super.addInformationFromPreconditions(info, factory, method, methodTree, methodElement);
List<? extends VariableTree> paramTrees = methodTree.getParameters();
for (VariableTree variableTree : paramTrees) {
if (TreeUtils.typeOf(variableTree).getKind() == TypeKind.CHAR) {
JavaExpression je = JavaExpression.fromVariableTree(variableTree);
info.insertValuePermitNondeterministic(je, aTypeFactory.NN);
}
}
}
Aggregations