Class ELCompiler
Every construct of the language is compiled to the equivalent Java expression. The property
accesses, the method invocations, the static references and the functions whose types are known at
compilation time are compiled to direct invocations, the remaining ones are compiled to the resolution
described in the sections 1.5 and 1.6 of the specification. The operators whose operand types are known
at compilation time are compiled to the Java operators the runtime would reach, see
inlineBinary(BinaryOperator, Typed, Typed).
- Since:
- 1.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe base object and the property of an lvalue.static final recordA compiled expression with the type known at compilation time, when there is one. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.micronaut.sourcegen.model.ExpressionDefCompiles an expression.io.micronaut.sourcegen.model.StatementDefcompileEvaluation(ELNode node, io.micronaut.sourcegen.model.ExpressionDef elContext, Function<io.micronaut.sourcegen.model.ExpressionDef, ELCompiler.Typed> body) Compiles the evaluation of an expression as the body of a method returning its result.@Nullable ELCompiler.LValuecompileLValue(ELNode node, io.micronaut.sourcegen.model.ExpressionDef elContext) Compiles the base object and the property of an lvalue, as described in the section 1.13 of the specification.compileTyped(ELNode node, io.micronaut.sourcegen.model.ExpressionDef ctx) Compiles an expression, with its static type.booleanevaluatesTo(io.micronaut.inject.ast.ClassElement expected) @Nullable io.micronaut.inject.ast.ClassElementstatic booleanhasAssignments(ELNode node) io.micronaut.inject.ast.ClassElementThe expected type inferred for an expression whose declaration omits it: the static type of the result, a primitive as the wrapper the evaluation returns,Objectwhen the compiler does not know the type.io.micronaut.inject.ast.ClassElementinferredType(ELNode node) The static type of an expression, for the return type of a method expression whose declaration omits it.io.micronaut.sourcegen.model.ExpressionDefinvokeRuntime(io.micronaut.sourcegen.model.ClassTypeDef owner, String name, io.micronaut.sourcegen.model.TypeDef returning, io.micronaut.sourcegen.model.ExpressionDef... values) Invokes a static method of the runtime with the signature the runtime actually declares, for the writers.
-
Constructor Details
-
ELCompiler
- Parameters:
context- The compilation context
-
-
Method Details
-
compile
public io.micronaut.sourcegen.model.ExpressionDef compile(ELNode node, io.micronaut.sourcegen.model.ExpressionDef elContext) Compiles an expression.- Parameters:
node- The parsed expressionelContext- The expression holding thejakarta.el.ELContext- Returns:
- The compiled expression
-
compileEvaluation
public io.micronaut.sourcegen.model.StatementDef compileEvaluation(ELNode node, io.micronaut.sourcegen.model.ExpressionDef elContext, Function<io.micronaut.sourcegen.model.ExpressionDef, ELCompiler.Typed> body) Compiles the evaluation of an expression as the body of a method returning its result.An identifier the expression resolves more than once is resolved once, into a local the references share, when nothing in the expression can change what the identifier denotes during the evaluation: the section 1.5.1 of the specification resolves an identifier through the lambda arguments, the variable mapper and the resolvers, and only the assignment and the semicolon operators can alter any of these within one evaluation. The bodies of the lambda expressions keep resolving through their own context.
When the expression holds a lambda expression, the context is first bound to a local: a Java lambda compiled from it captures the context, and the Java source writer of SourceGen 2.1.0 cannot render a captured method parameter, while its bytecode writer captures a local.
- Parameters:
node- The parsed expressionelContext- The expression holding thejakarta.el.ELContextbody- The compilation of the result with the context to use, once the shared identifiers are in place- Returns:
- The body of the method
-
evaluationType
public @Nullable io.micronaut.inject.ast.ClassElement evaluationType()- Returns:
- The static type of the result of the last
compileEvaluation(ELNode, ExpressionDef, Function), ornullwhen it is not known
-
inferredEvaluationType
public io.micronaut.inject.ast.ClassElement inferredEvaluationType()The expected type inferred for an expression whose declaration omits it: the static type of the result, a primitive as the wrapper the evaluation returns,Objectwhen the compiler does not know the type.- Returns:
- The inferred type
-
inferredType
The static type of an expression, for the return type of a method expression whose declaration omits it.- Parameters:
node- The parsed expression- Returns:
- The inferred type
-
evaluatesTo
public boolean evaluatesTo(io.micronaut.inject.ast.ClassElement expected) - Parameters:
expected- The expected type of a value expression- Returns:
- Whether the result of the last
compileEvaluation(ELNode, ExpressionDef, Function)is known to be of the expected type, so that the coercion of the section 1.23 of the specification is the identity
-
compileLValue
public @Nullable ELCompiler.LValue compileLValue(ELNode node, io.micronaut.sourcegen.model.ExpressionDef elContext) Compiles the base object and the property of an lvalue, as described in the section 1.13 of the specification.- Parameters:
node- The parsed expressionelContext- The expression holding thejakarta.el.ELContext- Returns:
- The lvalue or
nullwhen the expression is not an lvalue
-
invokeRuntime
public io.micronaut.sourcegen.model.ExpressionDef invokeRuntime(io.micronaut.sourcegen.model.ClassTypeDef owner, String name, io.micronaut.sourcegen.model.TypeDef returning, io.micronaut.sourcegen.model.ExpressionDef... values) Invokes a static method of the runtime with the signature the runtime actually declares, for the writers.- Parameters:
owner- The declaring typename- The method namereturning- The type the result is used asvalues- The arguments- Returns:
- The invocation
- See Also:
-
compileTyped
Compiles an expression, with its static type.- Parameters:
node- The parsed expressionctx- The expression holding thejakarta.el.ELContext- Returns:
- The compiled expression and its type
-
unresolvedIdentifiers
-
hasAssignments
- Parameters:
node- A parsed expression- Returns:
- Whether the expression assigns or sequences, which makes what an identifier denotes dynamic
-