Class ForgedMethod

  • All Implemented Interfaces:
    Method

    public class ForgedMethod
    extends Object
    implements Method
    This method will be generated in absence of a suitable abstract method to implement.
    Author:
    Sjaak Derksen
    • Constructor Detail

      • ForgedMethod

        public ForgedMethod​(String name,
                            ForgedMethod forgedMethod)
        creates a new ForgedMethod with the same arguments but with a new name
        Parameters:
        name - the new name
        forgedMethod - existing forge method
    • Method Detail

      • forParameterMapping

        public static ForgedMethod forParameterMapping​(String name,
                                                       Type sourceType,
                                                       Type returnType,
                                                       Method basedOn)
        Creates a new forged method with the given name for mapping a method parameter to a property.
        Parameters:
        name - the (unique name) for this method
        sourceType - the source type
        returnType - the return type.
        basedOn - the method that (originally) triggered this nested method generation.
        Returns:
        a new forge method
      • forPropertyMapping

        public static ForgedMethod forPropertyMapping​(String name,
                                                      Type sourceType,
                                                      Type returnType,
                                                      List<Parameter> parameters,
                                                      Method basedOn,
                                                      ForgedMethodHistory history,
                                                      MappingReferences mappingReferences,
                                                      boolean forgedNameBased)
        Creates a new forged method for mapping a bean property to a property
        Parameters:
        name - the (unique name) for this method
        sourceType - the source type
        returnType - the return type.
        parameters - other parameters (including the context + @MappingTarget
        basedOn - the method that (originally) triggered this nested method generation.
        history - a parent forged method if this is a forged method within a forged method
        mappingReferences - the mapping options for this method
        forgedNameBased - forges a name based (matched) mapping method
        Returns:
        a new forge method
      • forElementMapping

        public static ForgedMethod forElementMapping​(String name,
                                                     Type sourceType,
                                                     Type returnType,
                                                     Method basedOn,
                                                     ForgedMethodHistory history,
                                                     boolean forgedNameBased)
        Creates a new forged method for mapping a collection element, map key/value or stream element
        Parameters:
        name - the (unique name) for this method
        sourceType - the source type
        returnType - the return type.
        basedOn - the method that (originally) triggered this nested method generation.
        history - a parent forged method if this is a forged method within a forged method
        forgedNameBased - forges a name based (matched) mapping method
        Returns:
        a new forge method
      • forSubclassMapping

        public static ForgedMethod forSubclassMapping​(String name,
                                                      Type sourceType,
                                                      Type returnType,
                                                      Method basedOn,
                                                      MappingReferences mappingReferences,
                                                      ForgedMethodHistory history,
                                                      boolean forgedNameBased)
        Creates a new forged method for mapping a SubclassMapping element
        Parameters:
        name - the (unique name) for this method
        sourceType - the source type
        returnType - the return type.
        basedOn - the method that (originally) triggered this nested method generation.
        history - a parent forged method if this is a forged method within a forged method
        forgedNameBased - forges a name based (matched) mapping method
        Returns:
        a new forge method
      • matches

        public boolean matches​(List<Type> sourceTypes,
                               Type targetType)
        Description copied from interface: Method
        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
        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
      • getDeclaringMapper

        public Type getDeclaringMapper()
        Description copied from interface: Method
        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().
        Specified by:
        getDeclaringMapper in interface Method
        Returns:
        The declaring mapper type
      • getName

        public String getName()
        Description copied from interface: Method
        Returns then name of the method.
        Specified by:
        getName in interface Method
        Returns:
        method name
      • 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
      • getMappingTargetParameter

        public Parameter getMappingTargetParameter()
        Description copied from interface: Method
        Returns the parameter designated as mapping target (if present) MappingTarget
        Specified by:
        getMappingTargetParameter in interface Method
        Returns:
        mapping target parameter (when present) null otherwise.
      • getTargetTypeParameter

        public Parameter getTargetTypeParameter()
        Description copied from interface: Method
        Returns the parameter designated as target type (if present) TargetType
        Specified by:
        getTargetTypeParameter in interface Method
        Returns:
        target type parameter (when present) null otherwise.
      • getReturnType

        public Type getReturnType()
        Description copied from interface: Method
        Returns the return type of the method
        Specified by:
        getReturnType in interface Method
        Returns:
        return type
      • 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
      • isForgedNamedBased

        public boolean isForgedNamedBased()
      • addThrownTypes

        public void addThrownTypes​(List<Type> thrownTypesToAdd)
      • 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.
      • isLifecycleCallbackMethod

        public boolean isLifecycleCallbackMethod()
        Specified by:
        isLifecycleCallbackMethod in interface Method
        Returns:
        true, if the method represents a mapping lifecycle callback (Before/After mapping method)
      • 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.
      • 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.
      • isObjectFactory

        public boolean isObjectFactory()
        object factory mechanism not supported for forged 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
      • describe

        public String describe()
        Specified by:
        describe in interface Method
        Returns:
        the short name for error messages when verbose, full name when not
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object