Class SourceMethod
- java.lang.Object
-
- org.mapstruct.ap.internal.model.source.SourceMethod
-
- All Implemented Interfaces:
Method
public class SourceMethod extends java.lang.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
MappingMethodOptionswill be called in this case).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSourceMethod.Builder
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description privateSourceMethod(SourceMethod.Builder builder, MappingMethodOptions mappingMethodOptions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleanallParametersAreAssignable(java.util.List<Parameter> fromParams, java.util.List<Parameter> toParams)booleancanInheritFrom(SourceMethod method)static booleancontainsTargetTypeParameter(java.util.List<Parameter> parameters)java.lang.Stringdescribe()private booleandetermineIfIsObjectFactory()private booleandetermineIfIsPresenceCheck()AccessibilitygetAccessibility()Returns theAccessibilityof this method.java.util.List<SourceMethod>getApplicablePrototypeMethods()java.util.List<SourceMethod>getApplicableReversePrototypeMethods()java.util.List<Parameter>getContextParameters()returns the list of mapping context parameters, i.e.ParameterProvidedMethodsgetContextProvidedMethods()TypegetDeclaringMapper()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().TypegetDefiningType()javax.lang.model.element.ExecutableElementgetExecutable()ParametergetMappingTargetParameter()Returns the parameter designated as mapping target (if present)MappingTargetjava.lang.StringgetName()Returns then name of the method.MappingMethodOptionsgetOptions()java.util.List<java.lang.String>getParameterNames()java.util.List<Parameter>getParameters()In contrast toMethod.getSourceParameters()this method returns all parametersTypegetResultType()Returns the type of the result.TypegetReturnType()Returns the return type of the methodjava.util.List<Parameter>getSourceParameters()returns the list of 'true' source parameters excluding the parameter(s) that are designated as target, target type or context parameter.ParametergetTargetTypeParameter()Returns the parameter designated as target type (if present)TargetTypejava.util.List<Type>getThrownTypes()Returns all exceptions thrown by this methodjava.util.List<Type>getTypeParameters()Returns the formal type parameters of this method in declaration order.booleanhasObjectFactoryAnnotation()booleaninverses(SourceMethod method)booleanisAbstract()booleanisAfterMappingMethod()booleanisBeforeMappingMethod()booleanisDefault()Whether this method is Java 8 default methodbooleanisIterableMapping()booleanisLifecycleCallbackMethod()booleanisMapMapping()booleanisObjectFactory()Returns whether the meethod is designated as bean factory for mapping targetObjectFactorybooleanisPresenceCheck()Returns whether the method is designated as a presence check methodbooleanisRemovedEnumMapping()Enum Mapping was realized with @Mapping in stead of @ValueMapping.booleanisStatic()Whether this method is static or an instance methodbooleanisStreamMapping()booleanisUpdateMethod()booleanisValueMapping()The default enum mapping (no mappings specified) will from now on be handled as a value mapping.booleanmatches(java.util.List<Type> sourceTypes, Type targetType)Checks whether the provided sourceType and provided targetType match with the parameter respectively return type of the method.booleanoverridesMethod()Whether an implementation of this method must be generated or not.java.lang.StringtoString()-
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
-
-
-
-
Field Detail
-
typeUtils
private final TypeUtils typeUtils
-
typeFactory
private final TypeFactory typeFactory
-
declaringMapper
private final Type declaringMapper
-
executable
private final javax.lang.model.element.ExecutableElement executable
-
parameters
private final java.util.List<Parameter> parameters
-
mappingTargetParameter
private final Parameter mappingTargetParameter
-
targetTypeParameter
private final Parameter targetTypeParameter
-
isObjectFactory
private final boolean isObjectFactory
-
isPresenceCheck
private final boolean isPresenceCheck
-
returnType
private final Type returnType
-
accessibility
private final Accessibility accessibility
-
exceptionTypes
private final java.util.List<Type> exceptionTypes
-
mappingMethodOptions
private final MappingMethodOptions mappingMethodOptions
-
prototypeMethods
private final java.util.List<SourceMethod> prototypeMethods
-
mapperToImplement
private final Type mapperToImplement
-
sourceParameters
private final java.util.List<Parameter> sourceParameters
-
contextParameters
private final java.util.List<Parameter> contextParameters
-
contextProvidedMethods
private final ParameterProvidedMethods contextProvidedMethods
-
typeParameters
private final java.util.List<Type> typeParameters
-
parameterNames
private java.util.List<java.lang.String> parameterNames
-
applicablePrototypeMethods
private java.util.List<SourceMethod> applicablePrototypeMethods
-
applicableReversePrototypeMethods
private java.util.List<SourceMethod> applicableReversePrototypeMethods
-
isValueMapping
private java.lang.Boolean isValueMapping
-
isIterableMapping
private java.lang.Boolean isIterableMapping
-
isMapMapping
private java.lang.Boolean isMapMapping
-
isStreamMapping
private java.lang.Boolean isStreamMapping
-
hasObjectFactoryAnnotation
private final boolean hasObjectFactoryAnnotation
-
verboseLogging
private final boolean verboseLogging
-
-
Constructor Detail
-
SourceMethod
private SourceMethod(SourceMethod.Builder builder, MappingMethodOptions mappingMethodOptions)
-
-
Method Detail
-
determineIfIsObjectFactory
private boolean determineIfIsObjectFactory()
-
determineIfIsPresenceCheck
private boolean determineIfIsPresenceCheck()
-
getDeclaringMapper
public Type getDeclaringMapper()
Description copied from interface:MethodReturns 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:
getDeclaringMapperin interfaceMethod- Returns:
- The declaring mapper type
-
getExecutable
public javax.lang.model.element.ExecutableElement getExecutable()
- Specified by:
getExecutablein interfaceMethod
-
getName
public java.lang.String getName()
Description copied from interface:MethodReturns then name of the method.
-
getParameters
public java.util.List<Parameter> getParameters()
Description copied from interface:MethodIn contrast toMethod.getSourceParameters()this method returns all parameters- Specified by:
getParametersin interfaceMethod- Returns:
- all parameters
-
getSourceParameters
public java.util.List<Parameter> getSourceParameters()
Description copied from interface:Methodreturns the list of 'true' source parameters excluding the parameter(s) that are designated as target, target type or context parameter.- Specified by:
getSourceParametersin interfaceMethod- Returns:
- list of 'true' source parameters
-
getContextParameters
public java.util.List<Parameter> getContextParameters()
Description copied from interface:Methodreturns the list of mapping context parameters, i.e. those parameters that are annotated withContext.- Specified by:
getContextParametersin interfaceMethod- Returns:
- list of context parameters
-
getContextProvidedMethods
public ParameterProvidedMethods getContextProvidedMethods()
- Specified by:
getContextProvidedMethodsin interfaceMethod- Returns:
- a mapping between
Method.getContextParameters()to factory and lifecycle methods provided by them.
-
getParameterNames
public java.util.List<java.lang.String> getParameterNames()
- Specified by:
getParameterNamesin interfaceMethod- Returns:
- the names of the parameters of this mapping method
-
getResultType
public Type getResultType()
Description copied from interface:MethodReturns 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:
getResultTypein interfaceMethod- Returns:
- result type
-
getReturnType
public Type getReturnType()
Description copied from interface:MethodReturns the return type of the method- Specified by:
getReturnTypein interfaceMethod- Returns:
- return type
-
getAccessibility
public Accessibility getAccessibility()
Description copied from interface:MethodReturns theAccessibilityof this method.- Specified by:
getAccessibilityin interfaceMethod- Returns:
- the
Accessibilityof this method
-
inverses
public boolean inverses(SourceMethod method)
-
canInheritFrom
public boolean canInheritFrom(SourceMethod method)
-
getMappingTargetParameter
public Parameter getMappingTargetParameter()
Description copied from interface:MethodReturns the parameter designated as mapping target (if present)MappingTarget- Specified by:
getMappingTargetParameterin interfaceMethod- Returns:
- mapping target parameter (when present) null otherwise.
-
isObjectFactory
public boolean isObjectFactory()
Description copied from interface:MethodReturns whether the meethod is designated as bean factory for mapping targetObjectFactory- Specified by:
isObjectFactoryin interfaceMethod- Returns:
- true if it is a target bean factory.
-
getTargetTypeParameter
public Parameter getTargetTypeParameter()
Description copied from interface:MethodReturns the parameter designated as target type (if present)TargetType- Specified by:
getTargetTypeParameterin interfaceMethod- 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
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getApplicablePrototypeMethods
public java.util.List<SourceMethod> getApplicablePrototypeMethods()
-
getApplicableReversePrototypeMethods
public java.util.List<SourceMethod> getApplicableReversePrototypeMethods()
-
allParametersAreAssignable
private static boolean allParametersAreAssignable(java.util.List<Parameter> fromParams, java.util.List<Parameter> toParams)
-
overridesMethod
public boolean overridesMethod()
Whether an implementation of this method must be generated or not.- Specified by:
overridesMethodin interfaceMethod- Returns:
- true when an implementation is required
-
matches
public boolean matches(java.util.List<Type> sourceTypes, Type targetType)
Description copied from interface:MethodChecks 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(java.util.List<Parameter> parameters)
- Parameters:
parameters- the parameter list to check- Returns:
trueif the parameter list contains a parameter annotated with@TargetType
-
getThrownTypes
public java.util.List<Type> getThrownTypes()
Description copied from interface:MethodReturns all exceptions thrown by this method- Specified by:
getThrownTypesin interfaceMethod- Returns:
- exceptions thrown
-
getOptions
public MappingMethodOptions getOptions()
- Specified by:
getOptionsin interfaceMethod- Returns:
- the mapping options for this method
-
isStatic
public boolean isStatic()
Description copied from interface:MethodWhether this method is static or an instance method
-
isDefault
public boolean isDefault()
Description copied from interface:MethodWhether this method is Java 8 default method
-
getDefiningType
public Type getDefiningType()
- Specified by:
getDefiningTypein interfaceMethod- Returns:
- the Type (class or interface) that defines this method.
-
isLifecycleCallbackMethod
public boolean isLifecycleCallbackMethod()
- Specified by:
isLifecycleCallbackMethodin interfaceMethod- Returns:
true, if the method represents a mapping lifecycle callback (Before/After mapping method)
-
isPresenceCheck
public boolean isPresenceCheck()
Description copied from interface:MethodReturns whether the method is designated as a presence check method- Specified by:
isPresenceCheckin interfaceMethod- Returns:
trueif 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:
isUpdateMethodin 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 java.util.List<Type> getTypeParameters()
Description copied from interface:MethodReturns the formal type parameters of this method in declaration order.- Specified by:
getTypeParametersin interfaceMethod- Returns:
- the formal type parameters, or an empty list if there are none
-
-