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
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 the
new operator).- Author:
- Gunnar Morling
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.mapstruct.ap.internal.model.common.Assignment
Assignment.AssignmentTypeNested classes/interfaces inherited from interface org.mapstruct.ap.internal.writer.Writable
Writable.Context -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, List<ParameterBinding> parameterBindings) Creates a new reference to the given method. -
Method Summary
Modifier and TypeMethodDescriptioncreateUniqueVarName(String desiredName) Creates an unique safe (local) variable name.booleanstatic MethodReferenceforBuiltInMethod(BuiltInMethod method, ConversionContext contextParam) static MethodReferenceforConstructorInvocation(Type type, List<ParameterBinding> parameterBindings) static MethodReferenceforForgedMethod(Method method, List<ParameterBinding> parameterBindings) static MethodReferenceforMapperReference(Method method, MapperReference declaringMapper, List<ParameterBinding> parameterBindings) static MethodReferenceforMethodCall(String methodName) static MethodReferenceforMethodChaining(MethodReference... references) static MethodReferenceforParameterProvidedMethod(Method method, Parameter providingParameter, List<ParameterBinding> parameterBindings) static MethodReferenceforStaticBuilder(String builderCreationMethod, Type definingType) Returns a set containing thoseTypes referenced by this model element for which an import statement needs to be declared.getName()SeeAssignment.getSourceLoopVarName()(java.lang.String) }Returns the source parameter name, to which this assignment applies.the source presence checker referencethe source reference being a source-getter, a constant, nested method call, etc.the source type used in the matching processreturns all types exception types thrown by this assignment.getType()Returns whether the type of assignmentinthashCode()inferTypeWhenEnum(Type type) booleanbooleanbooleanbooleanbooleanisStatic()voidsetAssignment(Assignment assignment) An assignment in itself can wrap another assignment.voidsetSourceLocalVarName(String sourceLocalVarName) Replaces the sourceReference at the call site in the assignment in the template with this sourceLocalVarName.voidsetSourceLoopVarName(String sourceLoopVarName) Replaces the sourceLocalVar or sourceReference at the call site in the assignment in the template with this sourceLoopVarName.toString()Methods inherited from class org.mapstruct.ap.internal.writer.FreeMarkerWritable
getTemplateName, getTemplateNameForClass, write
-
Constructor Details
-
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;nullif the current mapper itselfprovidingParameter- The parameter providing the mapper, ornullif the method is defined by the mapper itself or bydeclaringMapper.parameterBindings- the parameter bindings of this method reference
-
-
Method Details
-
getDeclaringMapper
-
getProvidingParameter
-
getMapperVariableName
-
getContextParam
-
getAssignment
-
getName
-
getSourceParameters
-
setAssignment
Description copied from interface:AssignmentAn 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:
setAssignmentin interfaceAssignment- Parameters:
assignment- the assignment to set
-
getSourceReference
Description copied from interface:Assignmentthe source reference being a source-getter, a constant, nested method call, etc.- Specified by:
getSourceReferencein interfaceAssignment- Returns:
- source reference
-
getSourcePresenceCheckerReference
Description copied from interface:Assignmentthe source presence checker reference- Specified by:
getSourcePresenceCheckerReferencein interfaceAssignment- Returns:
- source reference
-
getSourceType
Description copied from interface:Assignmentthe source type used in the matching process- Specified by:
getSourceTypein interfaceAssignment- Returns:
- source type (can be null)
-
createUniqueVarName
Description copied from interface:AssignmentCreates an unique safe (local) variable name.- Specified by:
createUniqueVarNamein interfaceAssignment- Parameters:
desiredName- the desired name- Returns:
- the desired name, made unique in the scope of the bean mapping.
-
getSourceLocalVarName
Description copied from interface:Assignment- Specified by:
getSourceLocalVarNamein interfaceAssignment- Returns:
- local variable name (can be null if not set)
-
setSourceLocalVarName
Description copied from interface:AssignmentReplaces 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:
setSourceLocalVarNamein interfaceAssignment- Parameters:
sourceLocalVarName- source local variable name
-
getSourceLoopVarName
Description copied from interface:AssignmentSeeAssignment.getSourceLoopVarName()(java.lang.String) }- Specified by:
getSourceLoopVarNamein interfaceAssignment- Returns:
- loop variable (can be null if not set)
-
setSourceLoopVarName
Description copied from interface:AssignmentReplaces 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:
setSourceLoopVarNamein interfaceAssignment- Parameters:
sourceLoopVarName- loop variable
-
getSourceParameterName
Description copied from interface:AssignmentReturns 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:
getSourceParameterNamein interfaceAssignment- Returns:
- the source parameter name
-
isSourceReferenceParameter
public boolean isSourceReferenceParameter()- Specified by:
isSourceReferenceParameterin interfaceAssignment- Returns:
- true when the source reference is the source parameter (and not a property of the source parameter type)
-
getSingleSourceParameterType
- Returns:
- the type of the single source parameter that is not the
@TargetTypeparameter
-
getDefiningType
-
getImportTypes
Description copied from class:ModelElementReturns a set containing thoseTypes referenced by this model element for which an import statement needs to be declared.- Specified by:
getImportTypesin interfaceAssignment- Specified by:
getImportTypesin classModelElement- Returns:
- A set with type referenced by this model element. Must not be
null.
-
getThrownTypes
Description copied from interface:Assignmentreturns all types exception types thrown by this assignment.- Specified by:
getThrownTypesin interfaceAssignment- Returns:
- exceptions thrown
-
getType
Description copied from interface:AssignmentReturns whether the type of assignment- Specified by:
getTypein interfaceAssignment- Returns:
Assignment.AssignmentType
-
getReturnType
-
isCallingUpdateMethod
public boolean isCallingUpdateMethod()- Specified by:
isCallingUpdateMethodin interfaceAssignment
-
isStatic
public boolean isStatic() -
isConstructor
public boolean isConstructor() -
isMethodChaining
public boolean isMethodChaining() -
getMethodsToChain
-
getParameterBindings
-
inferTypeWhenEnum
-
hashCode
public int hashCode() -
equals
-
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
-
forMethodCall
-
forConstructorInvocation
public static MethodReference forConstructorInvocation(Type type, List<ParameterBinding> parameterBindings) -
forMethodChaining
-
toString
-