Search in sources :

Example 6 with FormalParameter

use of org.checkerframework.dataflow.expression.FormalParameter in project checker-framework by typetools.

the class StringToJavaExpression method atMethodDecl.

/**
 * Parses a string to a {@link JavaExpression} as if it were written at {@code method}. The
 * returned {@code JavaExpression} uses {@link FormalParameter}s to represent parameters. Use
 * {@link #atMethodBody(String, MethodTree, SourceChecker)} if parameters should be {@link
 * LocalVariable}s instead.
 *
 * @param expression a Java expression to parse
 * @param method method element 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 atMethodDecl(String expression, ExecutableElement method, SourceChecker checker) throws JavaExpressionParseException {
    TypeMirror enclosingType = ElementUtils.enclosingTypeElement(method).asType();
    ThisReference thisReference;
    if (ElementUtils.isStatic(method)) {
        // Can't use "this" on a static method
        thisReference = null;
    } else {
        thisReference = new ThisReference(enclosingType);
    }
    List<FormalParameter> parameters = JavaExpression.getFormalParameters(method);
    return JavaExpressionParseUtil.parse(expression, enclosingType, thisReference, parameters, null, checker.getPathToCompilationUnit(), checker.getProcessingEnvironment());
}
Also used : FormalParameter(org.checkerframework.dataflow.expression.FormalParameter) TypeMirror(javax.lang.model.type.TypeMirror) ThisReference(org.checkerframework.dataflow.expression.ThisReference)

Aggregations

FormalParameter (org.checkerframework.dataflow.expression.FormalParameter)6 TypeMirror (javax.lang.model.type.TypeMirror)5 ThisReference (org.checkerframework.dataflow.expression.ThisReference)5 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)3 MethodTree (com.sun.source.tree.MethodTree)2 VariableTree (com.sun.source.tree.VariableTree)2 ArrayList (java.util.ArrayList)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 VariableElement (javax.lang.model.element.VariableElement)2 LocalVariable (org.checkerframework.dataflow.expression.LocalVariable)2 ViewpointAdaptJavaExpression (org.checkerframework.dataflow.expression.ViewpointAdaptJavaExpression)2 AnnotationTree (com.sun.source.tree.AnnotationTree)1 ClassTree (com.sun.source.tree.ClassTree)1 ExpressionTree (com.sun.source.tree.ExpressionTree)1 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)1 MemberSelectTree (com.sun.source.tree.MemberSelectTree)1 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 ModifiersTree (com.sun.source.tree.ModifiersTree)1 NewClassTree (com.sun.source.tree.NewClassTree)1 Tree (com.sun.source.tree.Tree)1