Package org.mapstruct.ap.internal.model
Class HelperMethod
- java.lang.Object
-
- org.mapstruct.ap.internal.model.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 formatterCreateDecimalFormat
, which is used in 2 conversions (BigInteger to String and BigDecimal to String)- Author:
- Sjaak Derksen
-
-
Constructor Summary
Constructors Constructor Description HelperMethod()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.boolean
equals(Object obj)
equals based on classAccessibility
getAccessibility()
Returns theAccessibility
of this method.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.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()
Set<Type>
getImportTypes()
Returns the types used by this method for which import statements need to be generated.Parameter
getMappingTargetParameter()
mapping target parameter mechanism not supported for built-in methodsString
getName()
Returns then name of the method.abstract Parameter
getParameter()
There's currently only one parameter foreseen instead of a list of parameterList<String>
getParameterNames()
List<Parameter>
getParameters()
In contrast toMethod.getSourceParameters()
this method returns all parametersType
getResultType()
Returns the type of the result.List<Parameter>
getSourceParameters()
returns the list of 'true' source parameters excluding the parameter(s) that are designated as target, target type or context parameter.Parameter
getTargetTypeParameter()
target type parameter mechanism not supported for built-in methodsList<Type>
getThrownTypes()
Returns all exceptions thrown by this methodList<Type>
getTypeParameters()
Returns the formal type parameters of this method in declaration order.int
hashCode()
hashCode based on classboolean
isDefault()
Whether this method is Java 8 default methodboolean
isLifecycleCallbackMethod()
boolean
isObjectFactory()
object factory mechanism not supported for built-in methodsboolean
isStatic()
Whether this method is static or an instance methodboolean
isUpdateMethod()
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 this method overrides an abstract method.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mapstruct.ap.internal.model.source.Method
describe, getConditionOptions, getMappingSourceType, getOptions, getReturnType, isMappingTargetAssignableToReturnType
-
-
-
-
Method Detail
-
getName
public String getName()
Returns then name of the method.
-
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 variablesDefault 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.
-
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.
-
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 viaMapper#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 interfaceMethod
- Returns:
null
-
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
-
getMappingTargetParameter
public Parameter getMappingTargetParameter()
mapping target parameter mechanism not supported for built-in methods- Specified by:
getMappingTargetParameter
in interfaceMethod
- Returns:
null
-
getTargetTypeParameter
public Parameter getTargetTypeParameter()
target type parameter mechanism not supported for built-in methods- Specified by:
getTargetTypeParameter
in interfaceMethod
- Returns:
null
-
isObjectFactory
public boolean isObjectFactory()
object factory mechanism not supported for built-in methods- Specified by:
isObjectFactory
in interfaceMethod
- 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 interfaceMethod
- 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
-
equals
public boolean equals(Object obj)
equals based on class
-
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
- sourcereturnType
- 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
-
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
-
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
-
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
-
getParameterNames
public List<String> getParameterNames()
- Specified by:
getParameterNames
in interfaceMethod
- 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 interfaceMethod
- Returns:
- true when an abstract method is overridden.
-
getExecutable
public ExecutableElement getExecutable()
- Specified by:
getExecutable
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)
-
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
.
-
-