Class TypeLookup

java.lang.Object
io.micronaut.sourcegen.model.TypeLookup

@Internal public final class TypeLookup extends Object
Finds a type by its binary name while a file is written: the compiler's element where a context of the round is given - the only thing that knows a type compiled or generated in the same round - and else the class, loaded by reflection without being initialized.

A class that cannot be loaded is remembered per class loader, whose classpath does not change, so that the types a generated file names are not looked for again on every question asked about them. The elements a context finds are remembered for as long as the lookup is used.

Since:
2.3
  • Method Details

    • reflective

      public static TypeLookup reflective()
      Returns:
      The lookup of classes alone, through the class loader of the generators
    • of

      public static TypeLookup of(@Nullable io.micronaut.inject.visitor.VisitorContext context)
      Parameters:
      context - The context of the round, or null
      Returns:
      The lookup of the context's elements and of classes through the class loader of the generators
    • of

      public static TypeLookup of(@Nullable io.micronaut.inject.visitor.VisitorContext context, ClassLoader classLoader)
      Parameters:
      context - The context of the round, or null
      classLoader - The class loader classes are loaded through
      Returns:
      The lookup
    • find

      public @Nullable ClassTypeDef find(String name)
      A type by its binary name: the compiler's element where the context knows it, else the loaded class.
      Parameters:
      name - The binary name
      Returns:
      The type, or null where neither knows it
    • classElement

      public @Nullable io.micronaut.inject.ast.ClassElement classElement(String name)
      The compiler's element of a type.
      Parameters:
      name - The binary name
      Returns:
      The element, or null without a context, or where it does not know the type
    • loadClass

      public @Nullable Class<?> loadClass(String name)
      Loads a class by its binary name, or the name of a primitive, without initializing it.
      Parameters:
      name - The name
      Returns:
      The class, or null where the class loader has none of the name
    • loadClass

      public @Nullable Class<?> loadClass(TypeDef type)
      Loads the class of a type: the class of a parameterized type, and the array class of an array.
      Parameters:
      type - The type
      Returns:
      The class, or null for a type variable, a wildcard, or a class that cannot be loaded