@FunctionalInterface public interface StringToJavaExpression
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.
Modifier and Type | Method and Description |
---|---|
static JavaExpression |
atConstructorInvocation(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 JavaExpression |
atFieldAccess(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 JavaExpression |
atFieldDecl(String expression,
VariableElement fieldElement,
SourceChecker checker)
Parses a string to a
JavaExpression as if it were written at fieldElement . |
static JavaExpression |
atLambdaParameter(String expression,
LambdaExpressionTree lambdaTree,
TreePath parentPath,
SourceChecker checker)
Parses a string as if it were written at one of the parameters of
lambdaTree . |
static JavaExpression |
atMethodBody(String expression,
MethodTree methodTree,
SourceChecker checker)
Parses a string to a
JavaExpression as if it were written at methodTree . |
static JavaExpression |
atMethodDecl(String expression,
ExecutableElement method,
SourceChecker checker)
Parses a string to a
JavaExpression as if it were written at method . |
static JavaExpression |
atMethodInvocation(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 JavaExpression |
atMethodInvocation(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 JavaExpression |
atPath(String expression,
TreePath localVarPath,
SourceChecker checker)
Parses a string as if it were written at
localVarPath . |
static JavaExpression |
atTypeDecl(String expression,
TypeElement typeElement,
SourceChecker checker)
Parses a string to a
JavaExpression as if it were written at typeElement . |
@Nullable JavaExpression |
toJavaExpression(String stringExpr)
Convert a string to a
JavaExpression . |
@Nullable JavaExpression toJavaExpression(String stringExpr) throws JavaExpressionParseUtil.JavaExpressionParseException
JavaExpression
. Returns null
if no conversion exists.
Conversion includes parsing stringExpr
to a JavaExpression
and optionally
transforming the result of parsing into another JavaExpression
. An example of
transformation is viewpoint adaptation.
stringExpr
- a Java expressionJavaExpression
or null
if no conversion from stringExpr
existsJavaExpressionParseUtil.JavaExpressionParseException
- if stringExpr
cannot be parsed to a JavaExpression
static JavaExpression atTypeDecl(String expression, TypeElement typeElement, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
JavaExpression
as if it were written at typeElement
.expression
- a Java expression to parsetypeElement
- type element at which expression
is parsedchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atFieldDecl(String expression, VariableElement fieldElement, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
JavaExpression
as if it were written at fieldElement
.expression
- a Java expression to parsefieldElement
- variable element at which expression
is parsedchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atMethodDecl(String expression, ExecutableElement method, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
JavaExpression
as if it were written at method
. The
returned JavaExpression
uses FormalParameter
s to represent parameters. Use
atMethodBody(String, MethodTree, SourceChecker)
if parameters should be LocalVariable
s instead.expression
- a Java expression to parsemethod
- method element at which expression
is parsedchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atMethodBody(String expression, MethodTree methodTree, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
JavaExpression
as if it were written at methodTree
. The
returned JavaExpression
uses LocalVariable
s to represent parameters. Use atMethodDecl(String, ExecutableElement, SourceChecker)
if parameters should be FormalParameter
s instead.expression
- a Java expression to parsemethodTree
- method declaration tree at which expression
is parsedchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atMethodInvocation(String expression, MethodInvocationTree methodInvocationTree, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
expression
- a Java expression to parsemethodInvocationTree
- method invocation treechecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atMethodInvocation(String expression, MethodInvocationNode methodInvocationNode, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
expression
- a Java expression to parsemethodInvocationNode
- method invocation nodechecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atConstructorInvocation(String expression, NewClassTree newClassTree, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
expression
- a Java expression to parsenewClassTree
- constructor invocationchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atFieldAccess(String expression, MemberSelectTree fieldAccess, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
expression
- a Java expression to parsefieldAccess
- the field access treechecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atLambdaParameter(String expression, LambdaExpressionTree lambdaTree, TreePath parentPath, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
lambdaTree
.
Parameters of the lambda are expressed as LocalVariable
s.expression
- a Java expression to parselambdaTree
- the lambda treeparentPath
- path to the parent of lambdaTree
; required because the expression can
reference final local variables of the enclosing methodchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsedstatic JavaExpression atPath(String expression, TreePath localVarPath, SourceChecker checker) throws JavaExpressionParseUtil.JavaExpressionParseException
localVarPath
.expression
- a Java expression to parselocalVarPath
- location at which expression
is parsedchecker
- checker used to get the ProcessingEnvironment
and current CompilationUnitTree
JavaExpression
for expression
JavaExpressionParseUtil.JavaExpressionParseException
- if expression
cannot be parsed