Class GenericUtils


  • @Internal
    public class GenericUtils
    extends java.lang.Object
    Utility methods for dealing with generic type signatures.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected GenericUtils​(javax.lang.model.util.Elements elementUtils, javax.lang.model.util.Types typeUtils, ModelUtils modelUtils)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> alignNewGenericsInfo​(java.util.List<? extends javax.lang.model.element.TypeParameterElement> typeParameters, java.util.List<? extends javax.lang.model.type.TypeMirror> typeArguments, java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> genericsInfo)
      Takes the bound generic information and re-aligns for the new type.
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> alignNewGenericsInfo​(javax.lang.model.element.TypeElement typeElement, java.util.List<? extends javax.lang.model.type.TypeMirror> typeArguments, java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> genericsInfo)
      Takes a type element and the bound generic information and re-aligns for the new type.
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> buildGenericTypeArgumentElementInfo​(javax.lang.model.element.Element element)
      Builds type argument information for the given type.
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> buildGenericTypeArgumentElementInfo​(javax.lang.model.element.Element element, javax.lang.model.type.DeclaredType declaredType)
      Builds type argument information for the given type.
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> buildGenericTypeArgumentElementInfo​(javax.lang.model.element.Element element, javax.lang.model.type.DeclaredType declaredType, java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> boundTypes)
      Builds type argument information for the given type.
      protected java.util.Optional<javax.lang.model.type.TypeMirror> getFirstTypeArgument​(javax.lang.model.type.TypeMirror type)
      Return the first type argument for the given type mirror.
      java.util.List<? extends javax.lang.model.type.TypeMirror> interfaceGenericTypesFor​(javax.lang.model.element.TypeElement element, java.lang.String interfaceName)
      Finds the generic types for the given interface for the given class element.
      protected java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> resolveBoundTypes​(javax.lang.model.type.DeclaredType type)
      Resolve bound types for the given declared type.
      protected javax.lang.model.type.TypeMirror resolveTypeReference​(javax.lang.model.type.TypeMirror mirror)  
      protected javax.lang.model.type.TypeMirror resolveTypeReference​(javax.lang.model.type.TypeMirror mirror, java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> boundTypes)
      Resolve a type reference to use for the given type mirror taking into account generic type variables.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GenericUtils

        protected GenericUtils​(javax.lang.model.util.Elements elementUtils,
                               javax.lang.model.util.Types typeUtils,
                               ModelUtils modelUtils)
        Parameters:
        elementUtils - The Elements
        typeUtils - The Types
        modelUtils - The ModelUtils
    • Method Detail

      • buildGenericTypeArgumentElementInfo

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> buildGenericTypeArgumentElementInfo​(@NonNull
                                                                                                                                                                javax.lang.model.element.Element element)
        Builds type argument information for the given type.
        Parameters:
        element - The element
        Returns:
        The type argument information
      • buildGenericTypeArgumentElementInfo

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> buildGenericTypeArgumentElementInfo​(@NonNull
                                                                                                                                                                javax.lang.model.element.Element element,
                                                                                                                                                                @Nullable
                                                                                                                                                                javax.lang.model.type.DeclaredType declaredType)
        Builds type argument information for the given type.
        Parameters:
        element - The element
        declaredType - The declared type
        Returns:
        The type argument information
      • buildGenericTypeArgumentElementInfo

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> buildGenericTypeArgumentElementInfo​(@NonNull
                                                                                                                                                                javax.lang.model.element.Element element,
                                                                                                                                                                @Nullable
                                                                                                                                                                javax.lang.model.type.DeclaredType declaredType,
                                                                                                                                                                java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> boundTypes)
        Builds type argument information for the given type.
        Parameters:
        element - The element
        declaredType - The declared type
        boundTypes - The type variables
        Returns:
        The type argument information
      • interfaceGenericTypesFor

        public java.util.List<? extends javax.lang.model.type.TypeMirror> interfaceGenericTypesFor​(javax.lang.model.element.TypeElement element,
                                                                                                   java.lang.String interfaceName)
        Finds the generic types for the given interface for the given class element.
        Parameters:
        element - The class element
        interfaceName - The interface
        Returns:
        The generic types or an empty list
      • getFirstTypeArgument

        protected java.util.Optional<javax.lang.model.type.TypeMirror> getFirstTypeArgument​(javax.lang.model.type.TypeMirror type)
        Return the first type argument for the given type mirror. For example for Optional<String> this will return String.
        Parameters:
        type - The type
        Returns:
        The first argument.
      • resolveTypeReference

        protected javax.lang.model.type.TypeMirror resolveTypeReference​(javax.lang.model.type.TypeMirror mirror)
        Parameters:
        mirror - The TypeMirror
        Returns:
        The resolved type reference
      • resolveTypeReference

        protected javax.lang.model.type.TypeMirror resolveTypeReference​(javax.lang.model.type.TypeMirror mirror,
                                                                        java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> boundTypes)
        Resolve a type reference to use for the given type mirror taking into account generic type variables.
        Parameters:
        mirror - The mirror
        boundTypes - The already bound types for any type variable
        Returns:
        A type reference
      • resolveBoundTypes

        protected java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> resolveBoundTypes​(javax.lang.model.type.DeclaredType type)
        Resolve bound types for the given declared type.
        Parameters:
        type - The declaring type
        Returns:
        The type bounds
      • alignNewGenericsInfo

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror>> alignNewGenericsInfo​(javax.lang.model.element.TypeElement typeElement,
                                                                                                                                                 java.util.List<? extends javax.lang.model.type.TypeMirror> typeArguments,
                                                                                                                                                 java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> genericsInfo)
        Takes a type element and the bound generic information and re-aligns for the new type.
        Parameters:
        typeElement - The type element
        typeArguments - The type arguments
        genericsInfo - The generic info
        Returns:
        The aligned generics
      • alignNewGenericsInfo

        public java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> alignNewGenericsInfo​(java.util.List<? extends javax.lang.model.element.TypeParameterElement> typeParameters,
                                                                                                           java.util.List<? extends javax.lang.model.type.TypeMirror> typeArguments,
                                                                                                           java.util.Map<java.lang.String,​javax.lang.model.type.TypeMirror> genericsInfo)
        Takes the bound generic information and re-aligns for the new type.
        Parameters:
        typeParameters - The type parameters
        typeArguments - The type arguments
        genericsInfo - The generic info
        Returns:
        The aligned generics