Package org.mapstruct.ap.internal.model
Class MethodReference
- java.lang.Object
-
- org.mapstruct.ap.internal.writer.FreeMarkerWritable
-
- org.mapstruct.ap.internal.model.common.ModelElement
-
- org.mapstruct.ap.internal.model.MethodReference
-
- All Implemented Interfaces:
Assignment
,Writable
- Direct Known Subclasses:
LifecycleCallbackMethodReference
public class MethodReference extends ModelElement implements Assignment
Represents a reference to another method, e.g. used to map a bean property from source to target type or to instantiate the return value of a mapping method (rather than calling thenew
operator).- Author:
- Gunnar Morling
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.mapstruct.ap.internal.model.common.Assignment
Assignment.AssignmentType
-
Nested classes/interfaces inherited from interface org.mapstruct.ap.internal.writer.Writable
Writable.Context
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, List<ParameterBinding> parameterBindings)
Creates a new reference to the given method.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
createUniqueVarName(String desiredName)
Creates an unique safe (local) variable name.boolean
equals(Object obj)
static MethodReference
forBuiltInMethod(BuiltInMethod method, ConversionContext contextParam)
static MethodReference
forConstructorInvocation(Type type, List<ParameterBinding> parameterBindings)
static MethodReference
forForgedMethod(Method method, List<ParameterBinding> parameterBindings)
static MethodReference
forMapperReference(Method method, MapperReference declaringMapper, List<ParameterBinding> parameterBindings)
static MethodReference
forMethodCall(String methodName)
static MethodReference
forMethodChaining(MethodReference... references)
static MethodReference
forParameterProvidedMethod(Method method, Parameter providingParameter, List<ParameterBinding> parameterBindings)
static MethodReference
forStaticBuilder(String builderCreationMethod, Type definingType)
Assignment
getAssignment()
String
getContextParam()
MapperReference
getDeclaringMapper()
Type
getDefiningType()
Set<Type>
getImportTypes()
Returns a set containing thoseType
s referenced by this model element for which an import statement needs to be declared.String
getMapperVariableName()
List<MethodReference>
getMethodsToChain()
String
getName()
List<ParameterBinding>
getParameterBindings()
Parameter
getProvidingParameter()
Type
getReturnType()
Type
getSingleSourceParameterType()
String
getSourceLocalVarName()
String
getSourceLoopVarName()
SeeAssignment.getSourceLoopVarName()
(java.lang.String) }String
getSourceParameterName()
Returns the source parameter name, to which this assignment applies.List<Parameter>
getSourceParameters()
PresenceCheck
getSourcePresenceCheckerReference()
the source presence checker referenceString
getSourceReference()
the source reference being a source-getter, a constant, nested method call, etc.Type
getSourceType()
the source type used in the matching processList<Type>
getThrownTypes()
returns all types exception types thrown by this assignment.Assignment.AssignmentType
getType()
Returns whether the type of assignmentint
hashCode()
Type
inferTypeWhenEnum(Type type)
boolean
isCallingUpdateMethod()
boolean
isConstructor()
boolean
isMethodChaining()
boolean
isSourceReferenceParameter()
boolean
isStatic()
void
setAssignment(Assignment assignment)
An assignment in itself can wrap another assignment.void
setSourceLocalVarName(String sourceLocalVarName)
Replaces the sourceReference at the call site in the assignment in the template with this sourceLocalVarName.void
setSourceLoopVarName(String sourceLoopVarName)
Replaces the sourceLocalVar or sourceReference at the call site in the assignment in the template with this sourceLoopVarName.String
toString()
-
Methods inherited from class org.mapstruct.ap.internal.writer.FreeMarkerWritable
getTemplateName, getTemplateNameForClass, write
-
-
-
-
Constructor Detail
-
MethodReference
protected MethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, List<ParameterBinding> parameterBindings)
Creates a new reference to the given method.- Parameters:
method
- the target method of the referencedeclaringMapper
- the method declaring the mapper;null
if the current mapper itselfprovidingParameter
- The parameter providing the mapper, ornull
if the method is defined by the mapper itself or bydeclaringMapper
.parameterBindings
- the parameter bindings of this method reference
-
-
Method Detail
-
getDeclaringMapper
public MapperReference getDeclaringMapper()
-
getProvidingParameter
public Parameter getProvidingParameter()
-
getMapperVariableName
public String getMapperVariableName()
-
getContextParam
public String getContextParam()
-
getAssignment
public Assignment getAssignment()
-
getName
public String getName()
-
setAssignment
public void setAssignment(Assignment assignment)
Description copied from interface:Assignment
An assignment in itself can wrap another assignment. E.g.:- a MethodReference can wrap a TypeConversion, another MethodReference and ultimately a Simple
- a TypeConversion can wrap a MethodReference, and ultimately a Simple
- Specified by:
setAssignment
in interfaceAssignment
- Parameters:
assignment
- the assignment to set
-
getSourceReference
public String getSourceReference()
Description copied from interface:Assignment
the source reference being a source-getter, a constant, nested method call, etc.- Specified by:
getSourceReference
in interfaceAssignment
- Returns:
- source reference
-
getSourcePresenceCheckerReference
public PresenceCheck getSourcePresenceCheckerReference()
Description copied from interface:Assignment
the source presence checker reference- Specified by:
getSourcePresenceCheckerReference
in interfaceAssignment
- Returns:
- source reference
-
getSourceType
public Type getSourceType()
Description copied from interface:Assignment
the source type used in the matching process- Specified by:
getSourceType
in interfaceAssignment
- Returns:
- source type (can be null)
-
createUniqueVarName
public String createUniqueVarName(String desiredName)
Description copied from interface:Assignment
Creates an unique safe (local) variable name.- Specified by:
createUniqueVarName
in interfaceAssignment
- Parameters:
desiredName
- the desired name- Returns:
- the desired name, made unique in the scope of the bean mapping.
-
getSourceLocalVarName
public String getSourceLocalVarName()
Description copied from interface:Assignment
- Specified by:
getSourceLocalVarName
in interfaceAssignment
- Returns:
- local variable name (can be null if not set)
-
setSourceLocalVarName
public void setSourceLocalVarName(String sourceLocalVarName)
Description copied from interface:Assignment
Replaces the sourceReference at the call site in the assignment in the template with this sourceLocalVarName. The sourceLocalVarName can subsequently be used for e.g. null checking.- Specified by:
setSourceLocalVarName
in interfaceAssignment
- Parameters:
sourceLocalVarName
- source local variable name
-
getSourceLoopVarName
public String getSourceLoopVarName()
Description copied from interface:Assignment
SeeAssignment.getSourceLoopVarName()
(java.lang.String) }- Specified by:
getSourceLoopVarName
in interfaceAssignment
- Returns:
- loop variable (can be null if not set)
-
setSourceLoopVarName
public void setSourceLoopVarName(String sourceLoopVarName)
Description copied from interface:Assignment
Replaces the sourceLocalVar or sourceReference at the call site in the assignment in the template with this sourceLoopVarName. The sourceLocalVar can subsequently be used for e.g. null checking.- Specified by:
setSourceLoopVarName
in interfaceAssignment
- Parameters:
sourceLoopVarName
- loop variable
-
getSourceParameterName
public String getSourceParameterName()
Description copied from interface:Assignment
Returns the source parameter name, to which this assignment applies. Note: the source parameter itself might be mapped by this assignment, or one of its properties- Specified by:
getSourceParameterName
in interfaceAssignment
- Returns:
- the source parameter name
-
isSourceReferenceParameter
public boolean isSourceReferenceParameter()
- Specified by:
isSourceReferenceParameter
in interfaceAssignment
- Returns:
- true when the source reference is the source parameter (and not a property of the source parameter type)
-
getSingleSourceParameterType
public Type getSingleSourceParameterType()
- Returns:
- the type of the single source parameter that is not the
@TargetType
parameter
-
getDefiningType
public Type getDefiningType()
-
getImportTypes
public Set<Type> getImportTypes()
Description copied from class:ModelElement
Returns a set containing thoseType
s referenced by this model element for which an import statement needs to be declared.- Specified by:
getImportTypes
in interfaceAssignment
- Specified by:
getImportTypes
in classModelElement
- Returns:
- A set with type referenced by this model element. Must not be
null
.
-
getThrownTypes
public List<Type> getThrownTypes()
Description copied from interface:Assignment
returns all types exception types thrown by this assignment.- Specified by:
getThrownTypes
in interfaceAssignment
- Returns:
- exceptions thrown
-
getType
public Assignment.AssignmentType getType()
Description copied from interface:Assignment
Returns whether the type of assignment- Specified by:
getType
in interfaceAssignment
- Returns:
Assignment.AssignmentType
-
getReturnType
public Type getReturnType()
-
isCallingUpdateMethod
public boolean isCallingUpdateMethod()
- Specified by:
isCallingUpdateMethod
in interfaceAssignment
-
isStatic
public boolean isStatic()
-
isConstructor
public boolean isConstructor()
-
isMethodChaining
public boolean isMethodChaining()
-
getMethodsToChain
public List<MethodReference> getMethodsToChain()
-
getParameterBindings
public List<ParameterBinding> getParameterBindings()
-
forBuiltInMethod
public static MethodReference forBuiltInMethod(BuiltInMethod method, ConversionContext contextParam)
-
forForgedMethod
public static MethodReference forForgedMethod(Method method, List<ParameterBinding> parameterBindings)
-
forParameterProvidedMethod
public static MethodReference forParameterProvidedMethod(Method method, Parameter providingParameter, List<ParameterBinding> parameterBindings)
-
forMapperReference
public static MethodReference forMapperReference(Method method, MapperReference declaringMapper, List<ParameterBinding> parameterBindings)
-
forStaticBuilder
public static MethodReference forStaticBuilder(String builderCreationMethod, Type definingType)
-
forMethodCall
public static MethodReference forMethodCall(String methodName)
-
forConstructorInvocation
public static MethodReference forConstructorInvocation(Type type, List<ParameterBinding> parameterBindings)
-
forMethodChaining
public static MethodReference forMethodChaining(MethodReference... references)
-
-