Class JavaModelUtils

java.lang.Object
io.micronaut.inject.processing.JavaModelUtils

public class JavaModelUtils extends Object
Utility methods for Java model handling.
Since:
1.0
Author:
graemerocher
  • Field Details

    • NAME_TO_TYPE_MAP

      public static final Map<String,String> NAME_TO_TYPE_MAP
  • Constructor Details

    • JavaModelUtils

      public JavaModelUtils()
  • Method Details

    • resolveKind

      public static 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
    • resolveKind

      public static 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
    • isInterface

      public static boolean isInterface(Element element)
      Whether the given element is an interface.
      Parameters:
      element - The element
      Returns:
      True if it is
    • isRecord

      public static boolean isRecord(Element element)
      Whether the given element is an interface.
      Parameters:
      element - The element
      Returns:
      True if it is
    • isClass

      public static boolean isClass(Element element)
      Whether the given element is a class.
      Parameters:
      element - The element
      Returns:
      True if it is
    • isEnum

      public static boolean isEnum(Element element)
      Whether the given element is an enum.
      Parameters:
      element - The element
      Returns:
      True if it is
    • isClassOrInterface

      public static boolean isClassOrInterface(Element element)
      Whether the given element is a class or interface.
      Parameters:
      element - The element
      Returns:
      True if it is
    • getClassName

      public static String getClassName(TypeElement typeElement)
      Get the class name for the given type element. Handles NestingKind.
      Parameters:
      typeElement - The type element
      Returns:
      The class name
    • getClassNameWithoutPackage

      public static String getClassNameWithoutPackage(TypeElement typeElement)
      Get the class name for the given type element without the package. Handles NestingKind.
      Parameters:
      typeElement - The type element
      Returns:
      The class name
    • getPackageName

      public static String getPackageName(TypeElement typeElement)
    • getClassArrayName

      public static String getClassArrayName(TypeElement typeElement)
      Get the array class name for the given type element. Handles NestingKind.
      Parameters:
      typeElement - The type element
      Returns:
      The class name
    • isRecordOrRecordComponent

      public static boolean isRecordOrRecordComponent(Element e)
      Return whether this is a record or a component of a record.
      Parameters:
      e - The element
      Returns:
      True if it is
    • isRecordComponent

      public static boolean isRecordComponent(Element e)
      Return whether this is a component of a record.
      Parameters:
      e - The element
      Returns:
      True if it is
    • getTypeReference

      public static org.objectweb.asm.Type getTypeReference(TypedElement type)
      Return the type reference for a class.
      Parameters:
      type - The type
      Returns:
      The Type
    • getClassname

      public static String getClassname(TypedElement type)
      Return the type reference for a class.
      Parameters:
      type - The type
      Returns:
      The Type