Class JavaExpressionParseUtil
java.lang.Object
org.checkerframework.dataflow.expression.JavaExpressionParseUtil
Helper methods to parse a string that represents a restricted Java expression.
- See the Checker Framework Manual:
- Writing Java expressions as annotation
arguments, Annotations whose argument is a Java expression
(dependent type annotations)
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Ifs
is exactly a formal parameter, return its 1-based index.static JavaExpression
parse
(String expression, TypeMirror enclosingType, @Nullable ThisReference thisReference, @Nullable List<FormalParameter> parameters, @Nullable TreePath localVarPath, TreePath pathToCompilationUnit, ProcessingEnvironment env) Parses a string to aJavaExpression
.
-
Method Details
-
parse
public static JavaExpression parse(String expression, TypeMirror enclosingType, @Nullable ThisReference thisReference, @Nullable List<FormalParameter> parameters, @Nullable TreePath localVarPath, TreePath pathToCompilationUnit, ProcessingEnvironment env) throws JavaExpressionParseException Parses a string to aJavaExpression
.- Parameters:
expression
- the string expression to parseenclosingType
- type of the class that encloses the JavaExpressionthisReference
- the JavaExpression to which to parse "this", or null if "this" should not appear in the expression; not relevant to qualified "SomeClass.this" or "package.SomeClass.this"parameters
- list of JavaExpressions to which to parse formal parameter references such as "#2", or null if formal parameter references should not appear in the expressionlocalVarPath
- if non-null, the expression is parsed as if it were written at this location; affects only parsing of local variablespathToCompilationUnit
- required to use the underlying Javac APIenv
- the processing environment- Returns:
expression
as aJavaExpression
- Throws:
JavaExpressionParseException
- if the string cannot be parsed
-
parameterIndex
Ifs
is exactly a formal parameter, return its 1-based index. Returns -1 otherwise.- Parameters:
s
- a Java expression- Returns:
- the 1-based index of the formal parameter that
s
represents, or -1
-