Interface StringToJavaExpression
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This interface is both a functional interface, see 
toJavaExpression(String), and also a
 collection of static methods that convert a string to a JavaExpression at common locations.
 Some conversion routines merely do parsing. Other conversion routines parse and then transform
 the result of parsing into another JavaExpression; for all the static methods, this
 transformation is viewpoint-adaptation.
 
To parse a string "at a location" means to parse it as if it were written in an annotation that is written on that location.
- 
Method SummaryModifier and TypeMethodDescriptionstatic JavaExpressionatConstructorInvocation(String expression, NewClassTree newClassTree, SourceChecker checker) 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.static JavaExpressionatFieldAccess(String expression, MemberSelectTree fieldAccess, SourceChecker checker) uf found Parses a string as if it were written at the declaration of the field and then viewpoint-adapts the result to the use.static JavaExpressionatFieldDecl(String expression, VariableElement fieldElement, SourceChecker checker) Parses a string to aJavaExpressionas if it were written atfieldElement.static JavaExpressionatLambdaParameter(String expression, LambdaExpressionTree lambdaTree, TreePath parentPath, SourceChecker checker) Parses a string as if it were written at one of the parameters oflambdaTree.static JavaExpressionatMethodBody(String expression, MethodTree methodTree, SourceChecker checker) Parses a string to aJavaExpressionas if it were written atmethodTree.static JavaExpressionatMethodDecl(String expression, ExecutableElement method, SourceChecker checker) Parses a string to aJavaExpressionas if it were written atmethod.static JavaExpressionatMethodInvocation(String expression, MethodInvocationTree methodInvocationTree, SourceChecker checker) 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.static JavaExpressionatMethodInvocation(String expression, MethodInvocationNode methodInvocationNode, SourceChecker checker) 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.static JavaExpressionatPath(String expression, TreePath localVarPath, SourceChecker checker) Parses a string as if it were written atlocalVarPath.static JavaExpressionatTypeDecl(String expression, TypeElement typeElement, SourceChecker checker) Parses a string to aJavaExpressionas if it were written attypeElement.toJavaExpression(String stringExpr) Convert a string to aJavaExpression.
- 
Method Details- 
toJavaExpression@Nullable JavaExpression toJavaExpression(String stringExpr) throws JavaExpressionParseUtil.JavaExpressionParseException Convert a string to aJavaExpression. Returnsnullif no conversion exists.Conversion includes parsing stringExprto aJavaExpressionand optionally transforming the result of parsing into anotherJavaExpression. An example of transformation is viewpoint adaptation.- Parameters:
- stringExpr- a Java expression
- Returns:
- a JavaExpressionornullif no conversion fromstringExprexists
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- stringExprcannot be parsed to a- JavaExpression
 
- 
atTypeDeclstatic JavaExpression atTypeDecl(String expression, TypeElement typeElement, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string to aJavaExpressionas if it were written attypeElement.- Parameters:
- expression- a Java expression to parse
- typeElement- type element at which- expressionis parsed
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atFieldDeclstatic JavaExpression atFieldDecl(String expression, VariableElement fieldElement, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string to aJavaExpressionas if it were written atfieldElement.- Parameters:
- expression- a Java expression to parse
- fieldElement- variable element at which- expressionis parsed
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atMethodDeclstatic JavaExpression atMethodDecl(String expression, ExecutableElement method, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string to aJavaExpressionas if it were written atmethod. The returnedJavaExpressionusesFormalParameters to represent parameters. UseatMethodBody(String, MethodTree, SourceChecker)if parameters should beLocalVariables instead.- Parameters:
- expression- a Java expression to parse
- method- method element at which- expressionis parsed
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atMethodBodystatic JavaExpression atMethodBody(String expression, MethodTree methodTree, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string to aJavaExpressionas if it were written atmethodTree. The returnedJavaExpressionusesLocalVariables to represent parameters. UseatMethodDecl(String, ExecutableElement, SourceChecker)if parameters should beFormalParameters instead.- Parameters:
- expression- a Java expression to parse
- methodTree- method declaration tree at which- expressionis parsed
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atMethodInvocationstatic JavaExpression atMethodInvocation(String expression, MethodInvocationTree methodInvocationTree, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException 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.- Parameters:
- expression- a Java expression to parse
- methodInvocationTree- method invocation tree
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atMethodInvocationstatic JavaExpression atMethodInvocation(String expression, MethodInvocationNode methodInvocationNode, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException 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.- Parameters:
- expression- a Java expression to parse
- methodInvocationNode- method invocation node
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atConstructorInvocationstatic JavaExpression atConstructorInvocation(String expression, NewClassTree newClassTree, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException 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.- Parameters:
- expression- a Java expression to parse
- newClassTree- constructor invocation
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atFieldAccessstatic JavaExpression atFieldAccess(String expression, MemberSelectTree fieldAccess, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException uf found Parses a string as if it were written at the declaration of the field and then viewpoint-adapts the result to the use.- Parameters:
- expression- a Java expression to parse
- fieldAccess- the field access tree
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atLambdaParameterstatic JavaExpression atLambdaParameter(String expression, LambdaExpressionTree lambdaTree, TreePath parentPath, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string as if it were written at one of the parameters oflambdaTree. Parameters of the lambda are expressed asLocalVariables.- Parameters:
- expression- a Java expression to parse
- lambdaTree- the lambda tree
- parentPath- path to the parent of- lambdaTree; required because the expression can reference final local variables of the enclosing method
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
- 
atPathstatic JavaExpression atPath(String expression, TreePath localVarPath, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException Parses a string as if it were written atlocalVarPath.- Parameters:
- expression- a Java expression to parse
- localVarPath- location at which- expressionis parsed
- checker- checker used to get the- ProcessingEnvironmentand current- CompilationUnitTree
- Returns:
- a JavaExpressionforexpression
- Throws:
- JavaExpressionParseUtil.JavaExpressionParseException- if- expressioncannot be parsed
 
 
-