Package io.micronaut.sourcegen.model
Interface ExpressionDef
- All Known Subinterfaces:
VariableDef
- All Known Implementing Classes:
ExpressionDef.And
,ExpressionDef.CallInstanceMethod
,ExpressionDef.CallStaticMethod
,ExpressionDef.Cast
,ExpressionDef.Condition
,ExpressionDef.Constant
,ExpressionDef.Convert
,ExpressionDef.EqualsReferentially
,ExpressionDef.EqualsStructurally
,ExpressionDef.GetPropertyValue
,ExpressionDef.IfElse
,ExpressionDef.InvokeGetClassMethod
,ExpressionDef.InvokeHashCodeMethod
,ExpressionDef.NewArrayInitialized
,ExpressionDef.NewArrayOfSize
,ExpressionDef.NewInstance
,ExpressionDef.Or
,ExpressionDef.Switch
,ExpressionDef.SwitchYieldCase
,TypeDef.Primitive.PrimitiveInstance
,VariableDef.Field
,VariableDef.Local
,VariableDef.MethodParameter
,VariableDef.StaticField
,VariableDef.This
public sealed interface ExpressionDef
permits ExpressionDef.And, ExpressionDef.CallInstanceMethod, ExpressionDef.CallStaticMethod, ExpressionDef.Cast, ExpressionDef.Condition, ExpressionDef.Constant, ExpressionDef.Convert, ExpressionDef.EqualsReferentially, ExpressionDef.EqualsStructurally, ExpressionDef.InvokeGetClassMethod, ExpressionDef.GetPropertyValue, ExpressionDef.InvokeHashCodeMethod, ExpressionDef.IfElse, ExpressionDef.NewArrayInitialized, ExpressionDef.NewArrayOfSize, ExpressionDef.NewInstance, ExpressionDef.Or, ExpressionDef.Switch, ExpressionDef.SwitchYieldCase, TypeDef.Primitive.PrimitiveInstance, VariableDef
The expression definition.
- Since:
- 1.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final record
The and condition.static final record
The call an instance method expression.static final record
The call a static method expression.static final record
The cast expression.static final record
The condition operator.static final record
The constant expression.static final record
The convert variable expression.static final record
The referential equals expression.static final record
The structurally equals expression.static final record
The get property value expression.static final record
The if-else expression.static final record
The get class expression.static final record
The get hashCode 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 or condition.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 ExpressionDef
asConditionAnd
(ExpressionDef expression) The and 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
asConditionOr
(ExpressionDef expression) The or condition of this variable.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.default ExpressionDef.Cast
Cast expression to a different type.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.equalsReferentially
(ExpressionDef other) The referentially equals (==) of this expression and the other expression.default ExpressionDef.EqualsStructurally
equalsStructurally
(ExpressionDef other) The structurally equalsObject.equals(Object)
of this expression and the other expression.static ExpressionDef.Constant
default VariableDef.Field
Reference the field of this variable.default VariableDef.Field
Reference the field of this variable.default ExpressionDef.GetPropertyValue
getPropertyValue
(io.micronaut.inject.ast.PropertyElement propertyElement) The get property value expression.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<? extends ExpressionDef> parameters) The call the instance method expression.The invocation of theObject.getClass()
} or equivalent method for the expression.The invocation of theObject.hashCode()
or equivalent method for the 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
-
asConditionAnd
The and condition of this variable.- Parameters:
expression
- The expression of this variable- Returns:
- The "and" condition expression
- Since:
- 1.3
-
asConditionOr
The or condition of this variable.- Parameters:
expression
- The expression of this variable- Returns:
- The "or" condition expression
- Since:
- 1.3
-
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
-
cast
Cast expression to a different type.- Parameters:
type
- The type to cast to- Returns:
- The cast 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<? extends 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
-
invokeHashCode
The invocation of theObject.hashCode()
or equivalent method for the expression.- Returns:
- The hash code invocation
- Since:
- 1.2
-
invokeGetClass
The invocation of theObject.getClass()
} or equivalent method for the expression.- Returns:
- The get class invocation
- Since:
- 1.2
-
equalsStructurally
The structurally equalsObject.equals(Object)
of this expression and the other expression.- Parameters:
other
- The other expression to compare with- Returns:
- The equals expression
- Since:
- 1.3
-
equalsReferentially
The referentially equals (==) of this expression and the other expression.- Parameters:
other
- The other expression to compare with- Returns:
- The equals expression
- Since:
- 1.3
-
getPropertyValue
default ExpressionDef.GetPropertyValue getPropertyValue(io.micronaut.inject.ast.PropertyElement propertyElement) The get property value expression.- Parameters:
propertyElement
- The property element- Returns:
- The get property value expression
- Since:
- 1.3
-
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
-