Class HelperMethod

  • All Implemented Interfaces:
    Method
    Direct Known Subclasses:
    CreateDecimalFormat

    public abstract class HelperMethod
    extends Object
    implements Method
    A non mapping method to be generated. Can be called from for instance conversions or built-in methods as shared helper method. One example of such method is the creation of a decimal formatter CreateDecimalFormat, which is used in 2 conversions (BigInteger to String and BigDecimal to String)
    Author:
    Sjaak Derksen
    • Constructor Detail

      • HelperMethod

        public HelperMethod()
    • Method Detail

      • getName

        public String getName()
        Returns then name of the method.
        Specified by:
        getName in interface Method
        Returns:
        default method name is equal to class name of build in method name
      • getImportTypes

        public Set<Type> getImportTypes()
        Returns the types used by this method for which import statements need to be generated. Defaults to the empty set. To be overridden by implementations in case they make use of additional types (note that the parameter and return type don't need to be added).
        Returns:
        the types used by this method for which import statements need to be generated
      • matches

        public boolean matches​(List<Type> sourceTypes,
                               Type targetType)
        Checks whether the provided sourceType and provided targetType match with the parameter respectively return type of the method. The check also should incorporate wild card and generic type variables

        Default the targetType should be assignable to the returnType and the sourceType to the parameter, excluding generic type variables. When the implementor sees a need for this, this method can be overridden.

        Specified by:
        matches in interface Method
        Parameters:
        sourceTypes - the sourceTypes to match to the parameter
        targetType - the targetType to match to the returnType
        Returns:
        true when match
      • getSourceParameters

        public List<Parameter> getSourceParameters()
        Description copied from interface: Method
        returns the list of 'true' source parameters excluding the parameter(s) that are designated as target, target type or context parameter.
        Specified by:
        getSourceParameters in interface Method
        Returns:
        list of 'true' source parameters
      • getContextParameters

        public List<Parameter> getContextParameters()
        Description copied from interface: Method
        returns the list of mapping context parameters, i.e. those parameters that are annotated with Context.
        Specified by:
        getContextParameters in interface Method
        Returns:
        list of context parameters
      • getDeclaringMapper

        public final Type getDeclaringMapper()
        Returns the mapper type declaring this method if it is not declared by the mapper interface currently processed but by another mapper imported via Mapper#users().

        For built-in methods, the declaring mapper is always null as they will be added as private methods to the generated mapper.

        Specified by:
        getDeclaringMapper in interface Method
        Returns:
        null
      • getMappingTargetParameter

        public Parameter getMappingTargetParameter()
        mapping target parameter mechanism not supported for built-in methods
        Specified by:
        getMappingTargetParameter in interface Method
        Returns:
        null
      • getTargetTypeParameter

        public Parameter getTargetTypeParameter()
        target type parameter mechanism not supported for built-in methods
        Specified by:
        getTargetTypeParameter in interface Method
        Returns:
        null
      • isObjectFactory

        public boolean isObjectFactory()
        object factory mechanism not supported for built-in methods
        Specified by:
        isObjectFactory in interface Method
        Returns:
        false
      • getTypeParameters

        public List<Type> getTypeParameters()
        Description copied from interface: Method
        Returns the formal type parameters of this method in declaration order.
        Specified by:
        getTypeParameters in interface Method
        Returns:
        the formal type parameters, or an empty list if there are none
      • getContextParameter

        public String getContextParameter​(ConversionContext conversionContext)
        the conversion context is used to format an auxiliary parameter in the method call with context specific information such as a date format.
        Parameters:
        conversionContext - context
        Returns:
        null if no context parameter should be included "null" if there should be an explicit null call "'dateFormat'" for instance, to indicate how the build-in method should format the date
      • hashCode

        public int hashCode()
        hashCode based on class
        Overrides:
        hashCode in class Object
        Returns:
        hashCode
      • equals

        public boolean equals​(Object obj)
        equals based on class
        Overrides:
        equals in class Object
        Parameters:
        obj - other class
        Returns:
        true when classes are the same
      • doTypeVarsMatch

        public boolean doTypeVarsMatch​(Type parameter,
                                       Type returnType)
        Analyzes the Java Generic type variables in the parameter do match the type variables in the build in method same goes for the returnType.
        Parameters:
        parameter - source
        returnType - target
        Returns:
        true, iff the type variables match
      • getParameter

        public abstract Parameter getParameter()
        There's currently only one parameter foreseen instead of a list of parameter
        Returns:
        the parameter
      • getThrownTypes

        public List<Type> getThrownTypes()
        Description copied from interface: Method
        Returns all exceptions thrown by this method
        Specified by:
        getThrownTypes in interface Method
        Returns:
        exceptions thrown
      • getResultType

        public Type getResultType()
        Description copied from interface: Method
        Returns the type of the result. The result is defined as the type of the parameter designated with MappingTarget, or in absence the return type.
        Specified by:
        getResultType in interface Method
        Returns:
        result type
      • getParameterNames

        public List<String> getParameterNames()
        Specified by:
        getParameterNames in interface Method
        Returns:
        the names of the parameters of this mapping method
      • overridesMethod

        public boolean overridesMethod()
        Description copied from interface: Method
        Whether this method overrides an abstract method.
        Specified by:
        overridesMethod in interface Method
        Returns:
        true when an abstract method is overridden.
      • isStatic

        public boolean isStatic()
        Description copied from interface: Method
        Whether this method is static or an instance method
        Specified by:
        isStatic in interface Method
        Returns:
        true when static.
      • isDefault

        public boolean isDefault()
        Description copied from interface: Method
        Whether this method is Java 8 default method
        Specified by:
        isDefault in interface Method
        Returns:
        true when Java 8 default method
      • getDefiningType

        public Type getDefiningType()
        Specified by:
        getDefiningType in interface Method
        Returns:
        the Type (class or interface) that defines this method.
      • isLifecycleCallbackMethod

        public boolean isLifecycleCallbackMethod()
        Specified by:
        isLifecycleCallbackMethod in interface Method
        Returns:
        true, if the method represents a mapping lifecycle callback (Before/After mapping method)
      • isUpdateMethod

        public boolean isUpdateMethod()
        Specified by:
        isUpdateMethod in interface Method
        Returns:
        true, if the method is an update method, i.e. it has a parameter annotated with @MappingTarget.