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.
@FunctionalInterface public interface StringToJavaExpressionThis interface is both a functional interface, seetoJavaExpression(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 Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static JavaExpressionatConstructorInvocation(java.lang.String expression, com.sun.source.tree.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(java.lang.String expression, com.sun.source.tree.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(java.lang.String expression, javax.lang.model.element.VariableElement fieldElement, SourceChecker checker)Parses a string to aJavaExpressionas if it were written atfieldElement.static JavaExpressionatLambdaParameter(java.lang.String expression, com.sun.source.tree.LambdaExpressionTree lambdaTree, com.sun.source.util.TreePath parentPath, SourceChecker checker)Parses a string as if it were written at one of the parameters oflambdaTree.static JavaExpressionatMethodBody(java.lang.String expression, com.sun.source.tree.MethodTree methodTree, SourceChecker checker)Parses a string to aJavaExpressionas if it were written atmethodTree.static JavaExpressionatMethodDecl(java.lang.String expression, javax.lang.model.element.ExecutableElement method, SourceChecker checker)Parses a string to aJavaExpressionas if it were written atmethod.static JavaExpressionatMethodInvocation(java.lang.String expression, com.sun.source.tree.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(java.lang.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(java.lang.String expression, com.sun.source.util.TreePath localVarPath, SourceChecker checker)Parses a string as if it were written atlocalVarPath.static JavaExpressionatTypeDecl(java.lang.String expression, javax.lang.model.element.TypeElement typeElement, SourceChecker checker)Parses a string to aJavaExpressionas if it were written attypeElement.@Nullable JavaExpressiontoJavaExpression(java.lang.String stringExpr)Convert a string to aJavaExpression.
-
-
-
Method Detail
-
toJavaExpression
@Nullable JavaExpression toJavaExpression(java.lang.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- ifstringExprcannot be parsed to aJavaExpression
-
atTypeDecl
static JavaExpression atTypeDecl(java.lang.String expression, javax.lang.model.element.TypeElement typeElement, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
Parses a string to aJavaExpressionas if it were written attypeElement.- Parameters:
expression- a Java expression to parsetypeElement- type element at whichexpressionis parsedchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atFieldDecl
static JavaExpression atFieldDecl(java.lang.String expression, javax.lang.model.element.VariableElement fieldElement, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
Parses a string to aJavaExpressionas if it were written atfieldElement.- Parameters:
expression- a Java expression to parsefieldElement- variable element at whichexpressionis parsedchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atMethodDecl
static JavaExpression atMethodDecl(java.lang.String expression, javax.lang.model.element.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 parsemethod- method element at whichexpressionis parsedchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atMethodBody
static JavaExpression atMethodBody(java.lang.String expression, com.sun.source.tree.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 parsemethodTree- method declaration tree at whichexpressionis parsedchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atMethodInvocation
static JavaExpression atMethodInvocation(java.lang.String expression, com.sun.source.tree.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 parsemethodInvocationTree- method invocation treechecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atMethodInvocation
static JavaExpression atMethodInvocation(java.lang.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 parsemethodInvocationNode- method invocation nodechecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atConstructorInvocation
static JavaExpression atConstructorInvocation(java.lang.String expression, com.sun.source.tree.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 parsenewClassTree- constructor invocationchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atFieldAccess
static JavaExpression atFieldAccess(java.lang.String expression, com.sun.source.tree.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 parsefieldAccess- the field access treechecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atLambdaParameter
static JavaExpression atLambdaParameter(java.lang.String expression, com.sun.source.tree.LambdaExpressionTree lambdaTree, com.sun.source.util.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 parselambdaTree- the lambda treeparentPath- path to the parent oflambdaTree; required because the expression can reference final local variables of the enclosing methodchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
atPath
static JavaExpression atPath(java.lang.String expression, com.sun.source.util.TreePath localVarPath, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
Parses a string as if it were written atlocalVarPath.- Parameters:
expression- a Java expression to parselocalVarPath- location at whichexpressionis parsedchecker- checker used to get theProcessingEnvironmentand currentCompilationUnitTree- Returns:
- a
JavaExpressionforexpression - Throws:
JavaExpressionParseUtil.JavaExpressionParseException- ifexpressioncannot be parsed
-
-