Class SourceMethod
- java.lang.Object
-
- org.mapstruct.ap.internal.model.source.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SourceMethod.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canInheritFrom(SourceMethod method)
static boolean
containsTargetTypeParameter(List<Parameter> parameters)
String
describe()
Accessibility
getAccessibility()
Returns theAccessibility
of this method.List<SourceMethod>
getApplicablePrototypeMethods()
List<SourceMethod>
getApplicableReversePrototypeMethods()
ConditionMethodOptions
getConditionOptions()
List<Parameter>
getContextParameters()
returns the list of mapping context parameters, i.e. those parameters that are annotated withContext
.ParameterProvidedMethods
getContextProvidedMethods()
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 viaMapper#users()
.Type
getDefiningType()
ExecutableElement
getExecutable()
Parameter
getMappingTargetParameter()
Returns the parameter designated as mapping target (if present)MappingTarget
String
getName()
Returns then name of the method.MappingMethodOptions
getOptions()
List<String>
getParameterNames()
List<Parameter>
getParameters()
In contrast toMethod.getSourceParameters()
this method returns all parametersType
getResultType()
Returns the type of the result.Type
getReturnType()
Returns the return type of the methodList<Parameter>
getSourceParameters()
returns the list of 'true' source parameters excluding the parameter(s) that are designated as target, target type or context parameter.Parameter
getSourcePropertyNameParameter()
Parameter
getTargetPropertyNameParameter()
Parameter
getTargetTypeParameter()
Returns the parameter designated as target type (if present)TargetType
List<Type>
getThrownTypes()
Returns all exceptions thrown by this methodList<Type>
getTypeParameters()
Returns the formal type parameters of this method in declaration order.boolean
hasObjectFactoryAnnotation()
boolean
inverses(SourceMethod method)
boolean
isAbstract()
boolean
isAfterMappingMethod()
boolean
isBeforeMappingMethod()
boolean
isDefault()
Whether this method is Java 8 default methodboolean
isIterableMapping()
boolean
isLifecycleCallbackMethod()
boolean
isMapMapping()
boolean
isObjectFactory()
Returns whether the meethod is designated as bean factory for mapping targetObjectFactory
boolean
isRemovedEnumMapping()
Enum Mapping was realized with @Mapping in stead of @ValueMapping.boolean
isStatic()
Whether this method is static or an instance methodboolean
isStreamMapping()
boolean
isUpdateMethod()
boolean
isValueMapping()
The default enum mapping (no mappings specified) will from now on be handled as a value mapping.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.boolean
overridesMethod()
Whether an implementation of this method must be generated or not.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.mapstruct.ap.internal.model.source.Method
getMappingSourceType, isMappingTargetAssignableToReturnType
-
-
-
-
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 viaMapper#users()
.- Specified by:
getDeclaringMapper
in interfaceMethod
- Returns:
- The declaring mapper type
-
getExecutable
public ExecutableElement getExecutable()
- Specified by:
getExecutable
in interfaceMethod
-
getName
public String getName()
Description copied from interface:Method
Returns then name of the method.
-
getParameters
public List<Parameter> getParameters()
Description copied from interface:Method
In contrast toMethod.getSourceParameters()
this method returns all parameters- Specified by:
getParameters
in interfaceMethod
- Returns:
- all parameters
-
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 interfaceMethod
- 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 withContext
.- Specified by:
getContextParameters
in interfaceMethod
- Returns:
- list of context parameters
-
getContextProvidedMethods
public ParameterProvidedMethods getContextProvidedMethods()
- Specified by:
getContextProvidedMethods
in interfaceMethod
- Returns:
- a mapping between
Method.getContextParameters()
to factory and lifecycle methods provided by them.
-
getParameterNames
public List<String> getParameterNames()
- Specified by:
getParameterNames
in interfaceMethod
- 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 withMappingTarget
, or in absence the return type.- Specified by:
getResultType
in interfaceMethod
- Returns:
- result type
-
getReturnType
public Type getReturnType()
Description copied from interface:Method
Returns the return type of the method- Specified by:
getReturnType
in interfaceMethod
- Returns:
- return type
-
getAccessibility
public Accessibility getAccessibility()
Description copied from interface:Method
Returns theAccessibility
of this method.- Specified by:
getAccessibility
in interfaceMethod
- Returns:
- the
Accessibility
of this method
-
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 interfaceMethod
- 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 targetObjectFactory
- Specified by:
isObjectFactory
in interfaceMethod
- 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 interfaceMethod
- Returns:
- target type parameter (when present) null otherwise.
-
getSourcePropertyNameParameter
public Parameter getSourcePropertyNameParameter()
-
getTargetPropertyNameParameter
public Parameter getTargetPropertyNameParameter()
-
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 interfaceMethod
- 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
-
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 interfaceMethod
- Returns:
- exceptions thrown
-
getOptions
public MappingMethodOptions getOptions()
- Specified by:
getOptions
in interfaceMethod
- Returns:
- the mapping options for this method
-
getConditionOptions
public ConditionMethodOptions getConditionOptions()
- Specified by:
getConditionOptions
in interfaceMethod
-
isStatic
public boolean isStatic()
Description copied from interface:Method
Whether this method is static or an instance method
-
isDefault
public boolean isDefault()
Description copied from interface:Method
Whether this method is Java 8 default method
-
getDefiningType
public Type getDefiningType()
- Specified by:
getDefiningType
in interfaceMethod
- Returns:
- the Type (class or interface) that defines this method.
-
isLifecycleCallbackMethod
public boolean isLifecycleCallbackMethod()
- Specified by:
isLifecycleCallbackMethod
in interfaceMethod
- Returns:
true
, if the method represents a mapping lifecycle callback (Before/After mapping 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 interfaceMethod
- 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 interfaceMethod
- Returns:
- the formal type parameters, or an empty list if there are none
-
-