Class TypeUtil

java.lang.Object
dev.derklaro.aerogel.auto.internal.util.TypeUtil

@API(status=INTERNAL, since="1.0.1", consumers="dev.derklaro.aerogel.auto.internal") public final class TypeUtil extends Object
A utility class for working compile time with annotations
Since:
1.0.1
  • Field Details

  • Constructor Details

    • TypeUtil

      private TypeUtil()
  • Method Details

    • typesOfAnnotationValue

      @NotNull public static @NotNull List<? extends TypeMirror> typesOfAnnotationValue(@NotNull @NotNull Runnable getter)
      A tiny hack which simplifies the value reading of an annotation during compile time. The processor is not allowed to read values of an annotation directly (which is currently used to read the value of the Provides annotation) which will cause an MirroredTypesException. In the exception the compiler will then give us access to the mirrored types of the annotation value. There are some other ways around there which are very long and complicated but don't need the exception throwing, but in my opinion this is the best and cleanest way to get around the problem. Thanks Ralph!.
      Parameters:
      getter - a runnable which gets called and the thrown exception gets catched.
      Returns:
      the type mirrors of the annotation value.
      Throws:
      dev.derklaro.aerogel.AerogelException - if the method is not used in the intended way.
    • innermostComponentType

      @NotNull public static Map.Entry<TypeMirror,Integer> innermostComponentType(@NotNull @NotNull ArrayType arrayType)
      Extracts the innermost, non-array component type from the given array type, while keeping track of the given array depth.
      Parameters:
      arrayType - the array type to get the innermost component type from.
      Returns:
      a mapping of the innermost component type and the original array depth.
    • getBinaryName

      @NotNull public static @NotNull Name getBinaryName(@NotNull @NotNull Elements elements, @NotNull @NotNull Element element)
      Get the binary name of the given element. This method makes the assumption that the given element is a type element and will fail if that is not the case. It is up to the caller to ensure that the given element is a type element.
      Parameters:
      elements - the element utils instance for the current processing environment.
      element - the element to get the binary name of.
      Returns:
      the binary name of the given type element.
    • asRuntimeType

      @NotNull public static @NotNull String asRuntimeType(@NotNull @NotNull TypeMirror typeMirror, @NotNull @NotNull Types types, @NotNull @NotNull Elements elements)
      Converts the given type mirror to a runtime readable class name representation.
      Parameters:
      typeMirror - the type mirror to convert.
      types - the type utils instance for the current processing environment.
      elements - the element utils instance for the current processing environment.
      Returns:
      the given type mirror as a runtime readable class name string.