Package io.micronaut.sourcegen.model
Interface ExpressionDef
- All Known Subinterfaces:
VariableDef
- All Known Implementing Classes:
ExpressionDef.CallInstanceMethod
,ExpressionDef.CallStaticMethod
,ExpressionDef.Condition
,ExpressionDef.Constant
,ExpressionDef.Convert
,ExpressionDef.IfElse
,ExpressionDef.NewArrayInitialized
,ExpressionDef.NewArrayOfSize
,ExpressionDef.NewInstance
,ExpressionDef.Switch
,ExpressionDef.SwitchYieldCase
,VariableDef.Field
,VariableDef.Local
,VariableDef.MethodParameter
,VariableDef.StaticField
,VariableDef.This
public sealed interface ExpressionDef
permits ExpressionDef.CallInstanceMethod, ExpressionDef.CallStaticMethod, ExpressionDef.Condition, ExpressionDef.Constant, ExpressionDef.Convert, ExpressionDef.IfElse, ExpressionDef.NewArrayInitialized, ExpressionDef.NewArrayOfSize, ExpressionDef.NewInstance, ExpressionDef.Switch, ExpressionDef.SwitchYieldCase, VariableDef
The expression definition.
- Since:
- 1.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final record
The call an instance method expression.static final record
The call a static method expression.static final record
The condition operator.static final record
The constant expression.static final record
The convert variable expression.static final record
The if-else expression.static final record
The new array expression.static final record
The new array expression.static final record
The new instance expression.static final record
The switch expression.static final record
The switch yield case expression. -
Method Summary
Modifier and TypeMethodDescriptiondefault ExpressionDef
asCondition
(String op, ExpressionDef expression) The condition of this variable.default StatementDef
asConditionIf
(StatementDef statement) The conditional statement based on this expression.default ExpressionDef
asConditionIfElse
(ExpressionDef expression, ExpressionDef elseExpression) The conditional if else expression.default StatementDef
asConditionIfElse
(StatementDef statement, StatementDef elseStatement) The conditional statement based on this expression.default ExpressionDef.Switch
asExpressionSwitch
(TypeDef type, Map<ExpressionDef.Constant, ExpressionDef> cases) Turn this expression into an expression switch.default StatementDef.Switch
asStatementSwitch
(TypeDef type, Map<ExpressionDef.Constant, StatementDef> cases) Turn this expression into a statement switch.static ExpressionDef.Constant
Resolve a constant for the given type from the string.static @Nullable ExpressionDef
Resolve a constant for the given type from the string.default ExpressionDef
Convert this variable to a different type.static ExpressionDef.Constant
default VariableDef.Field
Reference the field of this variable.default VariableDef.Field
Reference the field of this variable.static ExpressionDef.NewInstance
instantiate
(ClassTypeDef type) The new instance expression.static ExpressionDef.NewInstance
instantiate
(ClassTypeDef type, List<ExpressionDef> values) The new instance expression.default ExpressionDef.CallInstanceMethod
invoke
(io.micronaut.inject.ast.MethodElement methodElement, ExpressionDef... parameters) The call the instance method expression.default ExpressionDef.CallInstanceMethod
invoke
(io.micronaut.inject.ast.MethodElement methodElement, List<ExpressionDef> parameters) The call the instance method expression.default ExpressionDef.CallInstanceMethod
The call the instance method expression.invoke
(VariableDef instance, String name, List<ExpressionDef> parameters, TypeDef returning) The call the instance method expression.default ExpressionDef.CallInstanceMethod
invoke
(String name, TypeDef returning, ExpressionDef... parameters) The call the instance method expression.default ExpressionDef.CallInstanceMethod
invoke
(String name, TypeDef returning, List<ExpressionDef> parameters) The call the instance method expression.invokeStatic
(ClassTypeDef typeDef, String name, List<ExpressionDef> parameters, TypeDef returning) The call the instance method expression.default ExpressionDef
default ExpressionDef
isNull()
default StatementDef.DefineAndAssign
Turn this expression into a new local variable.default StatementDef
newLocal
(String name, Function<VariableDef, StatementDef> fn) Turn this expression into a new local variable.static ExpressionDef.Constant
default StatementDef
The statement returning this expression.static ExpressionDef.Constant
type()
The type of the expression.default StatementDef.While
whileLoop
(StatementDef statement) Turn this expression into a while statement.
-
Method Details
-
asCondition
The condition of this variable.- Parameters:
op
- The operatorexpression
- The expression of this variable- Returns:
- The condition expression
- Since:
- 1.2
-
isNonNull
- Returns:
- Is non-null expression
- Since:
- 1.2
-
isNull
- Returns:
- Is null expression
- Since:
- 1.2
-
nullValue
- Returns:
- The null value expression
- Since:
- 1.2
-
trueValue
- Returns:
- The true value expression
- Since:
- 1.2
-
falseValue
- Returns:
- The true value expression
- Since:
- 1.2
-
returning
The statement returning this expression.- Returns:
- The statement returning this expression
-
asConditionIf
The conditional statement based on this expression.- Parameters:
statement
- The statement- Returns:
- The statement returning this expression
- Since:
- 1.2
-
asConditionIfElse
The conditional statement based on this expression.- Parameters:
statement
- The statementelseStatement
- The else statement- Returns:
- The statement returning this expression
- Since:
- 1.2
-
asConditionIfElse
The conditional if else expression.- Parameters:
expression
- The expressionelseExpression
- The else expression- Returns:
- The statement returning this expression
- Since:
- 1.2
-
newLocal
Turn this expression into a new local variable.- Parameters:
name
- The local name- Returns:
- A new local
- Since:
- 1.2
-
newLocal
Turn this expression into a new local variable.- Parameters:
name
- The local namefn
- The contextual function- Returns:
- A new local
- Since:
- 1.2
-
asExpressionSwitch
default ExpressionDef.Switch asExpressionSwitch(TypeDef type, Map<ExpressionDef.Constant, ExpressionDef> cases) Turn this expression into an expression switch.- Parameters:
type
- The expression typecases
- The cases- Returns:
- A new switch expression
- Since:
- 1.2
-
asStatementSwitch
default StatementDef.Switch asStatementSwitch(TypeDef type, Map<ExpressionDef.Constant, StatementDef> cases) Turn this expression into a statement switch.- Parameters:
type
- The expression typecases
- The cases- Returns:
- A new switch expression
- Since:
- 1.2
-
whileLoop
Turn this expression into a while statement.- Parameters:
statement
- The statement- Returns:
- A new switch expression
- Since:
- 1.2
-
convert
Convert this variable to a different type.- Parameters:
typeDef
- The type- Returns:
- the convert expression
- Since:
- 1.2
-
field
Reference the field of this variable.- Parameters:
fieldName
- The field typetypeDef
- Teh field type- Returns:
- The field variable
- Since:
- 1.2
-
field
Reference the field of this variable.- Parameters:
fieldDef
- The field definition- Returns:
- The field variable
- Since:
- 1.2
-
invoke
The call the instance method expression.- Parameters:
methodDef
- The method- Returns:
- The call to the instance method
- Since:
- 1.2
-
invoke
default ExpressionDef.CallInstanceMethod invoke(String name, TypeDef returning, ExpressionDef... parameters) The call the instance method expression.- Parameters:
name
- The method nameparameters
- The parametersreturning
- The returning- Returns:
- The call to the instance method
- Since:
- 1.2
-
invoke
default ExpressionDef.CallInstanceMethod invoke(String name, TypeDef returning, List<ExpressionDef> parameters) The call the instance method expression.- Parameters:
name
- The method nameparameters
- The parametersreturning
- The returning- Returns:
- The call to the instance method
- Since:
- 1.2
-
invoke
default ExpressionDef.CallInstanceMethod invoke(io.micronaut.inject.ast.MethodElement methodElement, ExpressionDef... parameters) The call the instance method expression.- Parameters:
methodElement
- The method elementparameters
- The parameters- Returns:
- The call to the instance method
- Since:
- 1.2
-
invoke
default ExpressionDef.CallInstanceMethod invoke(io.micronaut.inject.ast.MethodElement methodElement, List<ExpressionDef> parameters) The call the instance method expression.- Parameters:
methodElement
- The method elementparameters
- The parameters- Returns:
- The call to the instance method
- Since:
- 1.2
-
constant
@Nullable static @Nullable ExpressionDef constant(io.micronaut.inject.ast.ClassElement type, TypeDef typeDef, @Nullable @Nullable Object value) Resolve a constant for the given type from the string.- Parameters:
type
- The typetypeDef
- The type defvalue
- The string value- Returns:
- The constant
- Throws:
IllegalArgumentException
- if the constant is not supported.
-
constant
Resolve a constant for the given type from the string.- Parameters:
value
- The string value- Returns:
- The constant
- Throws:
IllegalArgumentException
- if the constant is not supported.- Since:
- 1.2
-
type
TypeDef type()The type of the expression.- Returns:
- The type
-
instantiate
The new instance expression.- Parameters:
type
- The type- Returns:
- The new instance
-
instantiate
The new instance expression.- Parameters:
type
- The typevalues
- The constructor values- Returns:
- The new instance
-
invoke
static ExpressionDef.CallInstanceMethod invoke(VariableDef instance, String name, List<ExpressionDef> parameters, TypeDef returning) The call the instance method expression.- Parameters:
instance
- The instancename
- The method nameparameters
- The parametersreturning
- The returning- Returns:
- The call to the instance method
-
invokeStatic
static ExpressionDef.CallStaticMethod invokeStatic(ClassTypeDef typeDef, String name, List<ExpressionDef> parameters, TypeDef returning) The call the instance method expression.- Parameters:
typeDef
- The class type defname
- The method nameparameters
- The parametersreturning
- The returning- Returns:
- The call to the static method
-