java.lang.Object
io.helidon.builder.processor.tools.BuilderTypeTools
All Implemented Interfaces:
TypeInfoCreatorProvider
Direct Known Subclasses:
TypeTools

public class BuilderTypeTools extends Object implements TypeInfoCreatorProvider
The default implementation for TypeInfoCreatorProvider. This also contains an abundance of other useful methods used for annotation processing.
  • Constructor Details

    • BuilderTypeTools

      @Deprecated public BuilderTypeTools()
      Deprecated.
      needed for service loader
      Default constructor. Service loaded.
  • Method Details

    • createTypeInfo

      public Optional<TypeInfo> createTypeInfo(TypeName annotationTypeName, TypeName typeName, TypeElement element, ProcessingEnvironment processingEnv, boolean wantDefaultMethods)
      Description copied from interface: TypeInfoCreatorProvider
      Creates a TypeInfo.
      Specified by:
      createTypeInfo in interface TypeInfoCreatorProvider
      Parameters:
      annotationTypeName - the annotation type name that triggered the creation
      typeName - the type name that is being processed that is annotated with the triggering annotation
      element - the element representative of the typeName
      processingEnv - the processing environment
      wantDefaultMethods - true to accept default methods (normally this is passed as false)
      Returns:
      the type info associated with the arguments being processed, or empty if not able to process the type
    • toElementInfo

      protected Collection<TypedElementName> toElementInfo(TypeElement element, ProcessingEnvironment processingEnv, boolean wantWhatWeCanAccept, boolean wantDefaultMethods)
      Translation the arguments to a collection of TypedElementName's.
      Parameters:
      element - the typed element (i.e., class)
      processingEnv - the processing env
      wantWhatWeCanAccept - pass true to get the elements we can accept to process, false for the other ones
      wantDefaultMethods - true to process default methods
      Returns:
      the collection of typed elements
    • canAccept

      protected boolean canAccept(ExecutableElement ee, boolean defineDefaultMethods)
      Returns true if the executable element passed is acceptable for processing. By default that means methods that are not static or default methods.
      Parameters:
      ee - the executable element
      defineDefaultMethods - true if we should also process default methods
      Returns:
      true if not able to accept
    • toTypeElement

      public static Optional<TypeElement> toTypeElement(TypeMirror typeMirror)
      Translates a TypeMirror into a TypeElement.
      Parameters:
      typeMirror - the type mirror
      Returns:
      the type element
    • createTypeNameFromDeclaredType

      public static Optional<DefaultTypeName> createTypeNameFromDeclaredType(DeclaredType type)
      Creates a name from a declared type during annotation processing.
      Parameters:
      type - the element type
      Returns:
      the associated type name instance
    • createTypeNameFromElement

      public static Optional<DefaultTypeName> createTypeNameFromElement(Element type)
      Creates a name from an element type during annotation processing.
      Parameters:
      type - the element type
      Returns:
      the associated type name instance
    • createTypeNameFromMirror

      public static Optional<DefaultTypeName> createTypeNameFromMirror(TypeMirror typeMirror)
      Converts a type mirror to a type name during annotation processing.
      Parameters:
      typeMirror - the type mirror
      Returns:
      the type name associated with the type mirror, or empty for generic type variables
    • findAnnotationMirror

      public static Optional<? extends AnnotationMirror> findAnnotationMirror(String annotationType, Collection<? extends AnnotationMirror> ams)
      Locate an annotation mirror by name.
      Parameters:
      annotationType - the annotation type to search for
      ams - the collection to search through
      Returns:
      the annotation mirror, or empty if not found
    • createAnnotationAndValueFromMirror

      public static Optional<AnnotationAndValue> createAnnotationAndValueFromMirror(AnnotationMirror am, Elements elements)
      Creates an instance from an annotation mirror during annotation processing.
      Parameters:
      am - the annotation mirror
      elements - the elements
      Returns:
      the new instance or empty if the annotation mirror passed is invalid
    • createAnnotationAndValueListFromElement

      public static List<AnnotationAndValue> createAnnotationAndValueListFromElement(Element e, Elements elements)
      Creates an instance from a variable element during annotation processing.
      Parameters:
      e - the variable/type element
      elements - the elements
      Returns:
      the list of annotations extracted from the element
    • extractValues

      public static Map<String,String> extractValues(AnnotationMirror am, Elements elements)
      Extracts values from the annotation mirror value.
      Parameters:
      am - the annotation mirror
      elements - the elements
      Returns:
      the extracted values
    • extractValues

      public static Map<String,String> extractValues(Map<? extends ExecutableElement,? extends AnnotationValue> values)
      Extracts values from the annotation element values.
      Parameters:
      values - the element values
      Returns:
      the extracted values
    • extractValue

      public static String extractValue(AnnotationMirror am, Elements elements)
      Extracts the singular value() value. Return value will always be non-null.
      Parameters:
      am - the annotation mirror
      elements - the elements
      Returns:
      the extracted values
    • createTypedElementNameFromElement

      public static TypedElementName createTypedElementNameFromElement(Element v, Elements elements)
      Creates an instance of a TypedElementName given its type and variable element from annotation processing.
      Parameters:
      v - the element (from annotation processing)
      elements - the elements
      Returns:
      the created instance
    • generatedStickerFor

      public static String generatedStickerFor(String generatorClassTypeName, String versionId)
      Produces the generated sticker annotation attribute contents.
      Parameters:
      generatorClassTypeName - the generator class type name
      versionId - the generator version identifier
      Returns:
      the generated sticker
    • copyrightHeaderFor

      public static String copyrightHeaderFor(String generatorClassTypeName)
      Produces the generated copy right header on code generated artifacts.
      Parameters:
      generatorClassTypeName - the generator class type name
      Returns:
      the generated comments