Class ELCompiler
java.lang.Object
io.micronaut.el.processor.compiler.ELCompiler
Lowers an expression syntax tree to the Micronaut SourceGen model.
Statically known accesses and operators become direct Java operations. The remainder uses the runtime resolution described in sections 1.5 and 1.6 of the specification.
- Since:
- 1.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe base and property of an lvalue.static final recordA compiled expression and its statically known type, when available. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList<io.micronaut.sourcegen.model.MethodDef> Returns the private helpers accumulated while compiling the current expression class.voidbeginClass(String className) Starts compiling one generated expression class.Returns the equality form of a generated expression, replacing declared function names with the methods bound to them as required by the Jakarta EL expression equality contract.io.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
-
beginClass
Starts compiling one generated expression class.- Parameters:
className- The generated class name
-
accessMethods
Returns the private helpers accumulated while compiling the current expression class.- Returns:
- The generated access helpers
-
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.Repeated stable identifiers share a local. Lambda bodies retain their own context, and an outer context captured by a generated Java lambda is first bound to a local for both source and bytecode generation.
- Parameters:
node- The parsed expressionelContext- The expression holding thejakarta.el.ELContextbody- Compiles the result after 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
-
canonical
-
hasAssignments
- Parameters:
node- A parsed expression- Returns:
- Whether the expression assigns or sequences, which makes what an identifier denotes dynamic
-