Class JavaExpressionParseUtil
java.lang.Object
org.checkerframework.framework.util.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)
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classAn exception that indicates a parse error.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionAnchored pattern for a formal parameter use; matches a string that is exactly a formal parameter use.protected static final StringRegular expression for a formal parameter use.Unanchored pattern for a formal parameter use; can be used to find all formal parameter uses.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic intIfsis exactly a formal parameter, return its 1-based index.static JavaExpressionparse(String expression, TypeMirror enclosingType, @Nullable ThisReference thisReference, @Nullable List<FormalParameter> parameters, @Nullable TreePath localVarPath, TreePath pathToCompilationUnit, ProcessingEnvironment env) Parses a string to aJavaExpression.
- 
Field Details- 
PARAMETER_REGEXRegular expression for a formal parameter use.- See Also:
 
- 
ANCHORED_PARAMETER_PATTERNAnchored pattern for a formal parameter use; matches a string that is exactly a formal parameter use.
- 
UNANCHORED_PARAMETER_PATTERNUnanchored pattern for a formal parameter use; can be used to find all formal parameter uses.
 
- 
- 
Constructor Details- 
JavaExpressionParseUtilpublic JavaExpressionParseUtil()
 
- 
- 
Method Details- 
parsepublic static JavaExpression parse(String expression, TypeMirror enclosingType, @Nullable ThisReference thisReference, @Nullable List<FormalParameter> parameters, @Nullable TreePath localVarPath, TreePath pathToCompilationUnit, ProcessingEnvironment env) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string to aJavaExpression.For most uses, clients should call one of the static methods in StringToJavaExpressionrather than calling this method directly.- Parameters:
- expression- the string expression to parse
- enclosingType- type of the class that encloses the JavaExpression
- thisReference- the JavaExpression to which to parse "this", or null if "this" should not appear in the expression
- 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 expression
- localVarPath- if non-null, the expression is parsed as if it were written at this location; affects only parsing of local variables
- pathToCompilationUnit- required to use the underlying Javac API
- env- the processing environment
- Returns:
- expressionas a- JavaExpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if the string cannot be parsed
 
- 
parameterIndexIfsis 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 srepresents, or -1
 
 
-