Class GenerationScope

java.lang.Object
io.micronaut.sourcegen.generator.GenerationScope

@Internal public final class GenerationScope extends Object
What the generation of one file resolves against: the outermost definition being written, whose inner types name it and each other, and the visitor context the file is written with, which knows the types only known by name. A generator creates one for each file it writes and passes it to the rules that depend on either.
Since:
2.3
  • Method Details

    • none

      public static GenerationScope none()
      Returns:
      The scope of no file: no definition is being written, and no context knows the types named
    • of

      public static GenerationScope of(@Nullable ObjectDef written, @Nullable io.micronaut.inject.visitor.VisitorContext visitorContext)
      Parameters:
      written - The outermost definition of the file being written, or null
      visitorContext - The context the file is written with, or null
      Returns:
      The scope
    • withoutVisitorContext

      public GenerationScope withoutVisitorContext()
      Returns:
      The same scope without the visitor context: the definitions of the file alone
    • written

      public @Nullable ObjectDef written()
      Returns:
      The outermost definition being written, or null
    • visitorContext

      public @Nullable io.micronaut.inject.visitor.VisitorContext visitorContext()
      Returns:
      The context the file is written with, or null
    • typeLookup

      public TypeLookup typeLookup()
      Returns:
      The lookup of the elements of the context and of the loaded classes
    • hierarchyLookup

      public TypeHierarchy.Lookup hierarchyLookup()
      Returns:
      What the hierarchy of a definition is looked up in: the definitions of the file being written - a member type named by its simple name, or naming its enclosing type by name - and the elements of the context
    • definitionsLookup

      public TypeHierarchy.Lookup definitionsLookup()
      Returns:
      The lookup of the definitions of the file being written alone
    • definitionOf

      public @Nullable ObjectDef definitionOf(@Nullable ClassTypeDef owner)
      The definition a type names, where it is one of the file being written.
      Parameters:
      owner - The type, or null
      Returns:
      The definition, or null where the type is no generated definition
    • definitionOf

      public @Nullable ObjectDef definitionOf(@Nullable ClassTypeDef owner, @Nullable ObjectDef current)
      The definition a method is invoked on, where it is generated: the one the owner names, or the one being written.
      Parameters:
      owner - The type declaring the invoked method, or null
      current - The definition being written, or null
      Returns:
      The definition, or null where the owner is no generated definition
    • enclosingVariables

      public List<TypeDef.TypeVariable> enclosingVariables(@Nullable ObjectDef definition)
      The variables of the types enclosing a definition that are in its scope: those of the enclosing class of an inner class - a member class that is not static - and of its enclosing class in turn, the nearest first. The definitions of the file being written tell which types enclose it.
      Parameters:
      definition - The definition
      Returns:
      The variables, empty for a top level type or a static member
    • elementLookup

      public @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> elementLookup()
      Returns:
      The lookup of the context's elements by name, or null without a context