Class ModelUtils

java.lang.Object
io.micronaut.annotation.processing.ModelUtils

@Internal public class ModelUtils extends Object
Provides utility method for working with the annotation processor AST.
Since:
1.0
Author:
Graeme Rocher
  • Constructor Details

    • ModelUtils

      protected ModelUtils(Elements elementUtils, Types typeUtils)
      Parameters:
      elementUtils - The Elements
      typeUtils - The Types
  • Method Details

    • getTypeUtils

      public Types getTypeUtils()
      Returns:
      The type utilities
    • resolveTypeElements

      public Stream<TypeElement> resolveTypeElements(Set<? extends Element> annotatedElements)
      Resolves type elements from the provided annotated elements.
      Parameters:
      annotatedElements - The elements to process
      Returns:
      the type elements
    • classElementFor

      @Nullable public final @Nullable TypeElement classElementFor(Element element)
      Obtains the TypeElement for an given element.
      Parameters:
      element - The element
      Returns:
      The TypeElement
    • isObjectClass

      public boolean isObjectClass(TypeElement element)
      Return whether the given element is the java.lang.Object class.
      Parameters:
      element - The element
      Returns:
      True if it is java.lang.Object
    • getAllInterfaces

      public Set<TypeElement> getAllInterfaces(TypeElement aClass)
      Parameters:
      aClass - A class
      Returns:
      All the interfaces
    • resolveKind

      public Optional<ElementKind> resolveKind(Element element, ElementKind expected)
      The Java APT throws an internal exception {code com.sun.tools.javac.code.Symbol$CompletionFailure} if a class is missing from the classpath and Element.getKind() is called. This method handles exceptions when calling the getKind() method to avoid this scenario and should be used instead of Element.getKind().
      Parameters:
      element - The element
      expected - The expected kind
      Returns:
      The kind if it is resolvable and matches the expected kind
    • resolveKind

      public Optional<ElementKind> resolveKind(Element element)
      The Java APT throws an internal exception {code com.sun.tools.javac.code.Symbol$CompletionFailure} if a class is missing from the classpath and Element.getKind() is called. This method handles exceptions when calling the getKind() method to avoid this scenario and should be used instead of Element.getKind().
      Parameters:
      element - The element
      Returns:
      The kind if it is resolvable