Class BuiltInMethod
- java.lang.Object
-
- org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod
-
- All Implemented Interfaces:
Method
- Direct Known Subclasses:
AbstractToXmlGregorianCalendar,CalendarToZonedDateTime,XmlGregorianCalendarToCalendar,XmlGregorianCalendarToDate,XmlGregorianCalendarToJodaDateTime,XmlGregorianCalendarToJodaLocalDate,XmlGregorianCalendarToJodaLocalDateTime,XmlGregorianCalendarToJodaLocalTime,XmlGregorianCalendarToLocalDate,XmlGregorianCalendarToLocalDateTime,XmlGregorianCalendarToString,ZonedDateTimeToCalendar
public abstract class BuiltInMethod extends Object implements Method
Represents a "built-in" mapping method which will be added as private method to the generated mapper. Built-in methods are used in cases where a simple conversation doesn't suffice, e.g. as several lines of source code or a try/catch block are required.- Author:
- Sjaak Derksen
-
-
Constructor Summary
Constructors Constructor Description BuiltInMethod()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Stringdescribe()booleandoTypeVarsMatch(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.booleanequals(Object obj)equals based on classAccessibilitygetAccessibility()Returns theAccessibilityof this method.ConstructorFragmentgetConstructorFragment()StringgetContextParameter(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.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()ExecutableElementgetExecutable()FieldReferencegetFieldReference()Set<Type>getImportTypes()Returns the types used by this method for which import statements need to be generated.ParametergetMappingTargetParameter()mapping target parameter mechanism not supported for built-in methodsStringgetName()Returns then name of the method.MappingMethodOptionsgetOptions()abstract ParametergetParameter()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 parametersTypegetResultType()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.ParametergetTargetTypeParameter()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.inthashCode()hashCode based on classbooleanisDefault()Whether this method is Java 8 default methodbooleanisLifecycleCallbackMethod()booleanisObjectFactory()object factory mechanism not supported for built-in methodsbooleanisStatic()Whether this method is static or an instance methodbooleanisUpdateMethod()booleanmatches(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 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
getConditionOptions, getMappingSourceType, 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: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 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.
-
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
nullas they will be added as private methods to the generated mapper.- Specified by:
getDeclaringMapperin interfaceMethod- Returns:
null
-
getParameters
public List<Parameter> getParameters()
Description copied from interface:MethodIn contrast toMethod.getSourceParameters()this method returns all parameters- Specified by:
getParametersin interfaceMethod- Returns:
- all parameters
-
getMappingTargetParameter
public Parameter getMappingTargetParameter()
mapping target parameter mechanism not supported for built-in methods- Specified by:
getMappingTargetParameterin interfaceMethod- Returns:
null
-
getTargetTypeParameter
public Parameter getTargetTypeParameter()
target type parameter mechanism not supported for built-in methods- Specified by:
getTargetTypeParameterin interfaceMethod- Returns:
null
-
isObjectFactory
public boolean isObjectFactory()
object factory mechanism not supported for built-in methods- Specified by:
isObjectFactoryin interfaceMethod- Returns:
- false
-
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
-
getTypeParameters
public 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
-
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:MethodReturns theAccessibilityof this method.- Specified by:
getAccessibilityin interfaceMethod- Returns:
- the
Accessibilityof this method
-
getThrownTypes
public List<Type> getThrownTypes()
Description copied from interface:MethodReturns all exceptions thrown by this method- Specified by:
getThrownTypesin interfaceMethod- Returns:
- exceptions thrown
-
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
-
getParameterNames
public List<String> getParameterNames()
- Specified by:
getParameterNamesin interfaceMethod- Returns:
- the names of the parameters of this mapping method
-
overridesMethod
public boolean overridesMethod()
Description copied from interface:MethodWhether this method overrides an abstract method.- Specified by:
overridesMethodin interfaceMethod- Returns:
- true when an abstract method is overridden.
-
getExecutable
public ExecutableElement getExecutable()
- Specified by:
getExecutablein interfaceMethod
-
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)
-
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.
-
getOptions
public MappingMethodOptions getOptions()
- Specified by:
getOptionsin interfaceMethod- Returns:
- the mapping options for this method
-
getFieldReference
public FieldReference getFieldReference()
-
getConstructorFragment
public ConstructorFragment getConstructorFragment()
-
-