Class SourceMethod

  • All Implemented Interfaces:
    Method

    public class SourceMethod
    extends Object
    implements Method
    Represents a mapping method with source and target type and the mappings between the properties of source and target type.

    A method can either be configured by itself or by another method for the inverse mapping direction (the appropriate setter on MappingMethodOptions will be called in this case).

    Author:
    Gunnar Morling
    • Method Detail

      • 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
      • getParameterNames

        public List<String> getParameterNames()
        Specified by:
        getParameterNames in interface Method
        Returns:
        the names of the parameters of this mapping method
      • 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
      • 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
      • inverses

        public boolean inverses​(SourceMethod method)
      • canInheritFrom

        public boolean canInheritFrom​(SourceMethod method)
      • 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.
      • isObjectFactory

        public boolean isObjectFactory()
        Description copied from interface: Method
        Returns whether the meethod is designated as bean factory for mapping target ObjectFactory
        Specified by:
        isObjectFactory in interface Method
        Returns:
        true if it is a target bean factory.
      • 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.
      • isIterableMapping

        public boolean isIterableMapping()
      • isStreamMapping

        public boolean isStreamMapping()
      • isMapMapping

        public boolean isMapMapping()
      • isRemovedEnumMapping

        public boolean isRemovedEnumMapping()
        Enum Mapping was realized with @Mapping in stead of @ValueMapping. @Mapping is no longer supported.
        Returns:
        true when @Mapping is used in stead of @ValueMapping
      • isValueMapping

        public boolean isValueMapping()
        The default enum mapping (no mappings specified) will from now on be handled as a value mapping. If there are any @Mapping / @Mappings defined on the method, then the deprecated enum behavior should be executed.
        Returns:
        whether (true) or not (false) to execute value mappings
      • getApplicablePrototypeMethods

        public List<SourceMethod> getApplicablePrototypeMethods()
      • getApplicableReversePrototypeMethods

        public List<SourceMethod> getApplicableReversePrototypeMethods()
      • overridesMethod

        public boolean overridesMethod()
        Whether an implementation of this method must be generated or not.
        Specified by:
        overridesMethod in interface Method
        Returns:
        true when an implementation is required
      • 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
      • containsTargetTypeParameter

        public static boolean containsTargetTypeParameter​(List<Parameter> parameters)
        Parameters:
        parameters - the parameter list to check
        Returns:
        true if the parameter list contains a parameter annotated with @TargetType
      • 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
      • 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)
      • isPresenceCheck

        public boolean isPresenceCheck()
        Description copied from interface: Method
        Returns whether the method is designated as a presence check method
        Specified by:
        isPresenceCheck in interface Method
        Returns:
        true if it is a presence check method
      • isAfterMappingMethod

        public boolean isAfterMappingMethod()
      • isBeforeMappingMethod

        public boolean isBeforeMappingMethod()
      • isAbstract

        public boolean isAbstract()
        Returns:
        returns true for interface methods (see jls 9.4) lacking a default or static modifier and for abstract methods
      • 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.
      • hasObjectFactoryAnnotation

        public boolean hasObjectFactoryAnnotation()
      • 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