Class CompilationContext

java.lang.Object
io.micronaut.el.processor.compiler.CompilationContext

@Internal public final class CompilationContext extends Object
The compilation time counterpart of a jakarta.el.ELContext.

It holds the statically known types of the variables, the imported classes and packages, and the functions of the expressions of a type, as declared with io.micronaut.el.annotation.ELEnvironment.

Since:
1.0
Author:
Denis Stepanov
  • Constructor Details

    • CompilationContext

      public CompilationContext(io.micronaut.inject.visitor.VisitorContext visitorContext, io.micronaut.inject.ast.Element originatingElement, ELFunctionDiscovery discovery, Map<String, io.micronaut.inject.ast.ClassElement> variables, Map<String, io.micronaut.inject.ast.ClassElement> importedClasses, List<String> importedPackages, List<io.micronaut.inject.ast.ClassElement> staticImports, Map<String, io.micronaut.inject.ast.MethodElement> functions)
      Parameters:
      visitorContext - The visitor context
      originatingElement - The element the expressions are declared on
      discovery - The functions discovered without a declaration
      variables - The types of the variables by name
      importedClasses - The imported classes by simple name
      importedPackages - The imported packages
      staticImports - The classes imported statically
      functions - The functions by qualified name
  • Method Details

    • getOriginatingElement

      public io.micronaut.inject.ast.Element getOriginatingElement()
      Returns:
      The element the expressions are declared on, where the diagnostics are reported
    • getVisitorContext

      public io.micronaut.inject.visitor.VisitorContext getVisitorContext()
      Returns:
      The visitor context
    • variableType

      public @Nullable io.micronaut.inject.ast.ClassElement variableType(String name)
      Parameters:
      name - The name of the variable
      Returns:
      The declared type of the variable or null when the variable is not declared
    • isLambdaParameter

      public boolean isLambdaParameter(String name)
      Parameters:
      name - The name
      Returns:
      True when the name is a parameter of one of the enclosing lambda expressions
    • lambdaParameter

      public @Nullable ELCompiler.Typed lambdaParameter(String name)
      Parameters:
      name - The name
      Returns:
      The compiled parameter of the innermost enclosing lambda expression declaring the name, or null when no enclosing lambda expression declares it
    • inValueLambda

      public boolean inValueLambda()
      Returns:
      Whether the compilation is inside the body of a lambda expression compiled to a value, which may be invoked later, with another context, so that nothing of the evaluation can be shared with it
    • enterLambdaScope

      public void enterLambdaScope(Map<String, ELCompiler.Typed> parameters, boolean withinEvaluation)
      Enters the scope of a lambda expression.
      Parameters:
      parameters - The formal parameters by name, compiled to the Java parameters holding them
      withinEvaluation - Whether the lambda runs within the evaluation it is written in, as a Java lambda passed to a method does, rather than as a value invoked later
    • exitLambdaScope

      public void exitLambdaScope()
      Exits the scope of a lambda expression.
    • resolveClass

      public @Nullable io.micronaut.inject.ast.ClassElement resolveClass(String simpleName)
      Resolves a class by its simple name, as described in the section 1.24.2 of the specification.
      Parameters:
      simpleName - The simple name
      Returns:
      The class or null when the name is not an imported class
    • resolveStaticField

      public @Nullable io.micronaut.inject.ast.FieldElement resolveStaticField(String name)
      Resolves a static field imported statically, as described in the section 1.24.2 of the specification.
      Parameters:
      name - The name of the field
      Returns:
      The field or null
    • resolveStaticMethod

      public @Nullable io.micronaut.inject.ast.MethodElement resolveStaticMethod(String name, int arguments)
      Resolves a static method imported statically, as described in the section 1.24.2 of the specification.
      Parameters:
      name - The name of the method
      arguments - The number of arguments
      Returns:
      The method or null
    • resolveFunction

      public @Nullable io.micronaut.inject.ast.MethodElement resolveFunction(String prefix, String localName)
      Parameters:
      prefix - The namespace prefix
      localName - The local name
      Returns:
      The function or null when the function is not declared
    • qualifiedFunctionName

      public static String qualifiedFunctionName(String prefix, String localName)
      Parameters:
      prefix - The namespace prefix
      localName - The local name
      Returns:
      The qualified name of a function