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 thenewoperator).
-
-
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
-
-
Field Summary
Fields Modifier and Type Field Description private AssignmentassignmentA reference to another mapping method or typeConversion in case this is a two-step mapping, e.g.private java.lang.StringcontextParamIn case this reference targets a built-in method, allows to pass specific context information to the invoked method.private MapperReferencedeclaringMapperprivate TypedefiningTypeprivate java.util.Set<Type>importTypesprivate booleanisConstructorprivate booleanisMethodChainingprivate booleanisStaticprivate booleanisUpdateMethodprivate java.util.List<MethodReference>methodsToChainprivate java.lang.Stringnameprivate java.util.List<ParameterBinding>parameterBindingsprivate ParameterprovidingParameterprivate TypereturnTypeprivate java.util.List<Parameter>sourceParametersprivate java.util.List<Type>thrownTypes
-
Constructor Summary
Constructors Modifier Constructor Description privateMethodReference(java.lang.String name, Type definingType, boolean isStatic)privateMethodReference(Type definingType, java.util.List<ParameterBinding> parameterBindings)privateMethodReference(MethodReference... references)privateMethodReference(BuiltInMethod method, ConversionContext contextParam)protectedMethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, java.util.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 java.lang.StringcreateUniqueVarName(java.lang.String desiredName)Creates an unique safe (local) variable name.booleanequals(java.lang.Object obj)static MethodReferenceforBuiltInMethod(BuiltInMethod method, ConversionContext contextParam)static MethodReferenceforConstructorInvocation(Type type, java.util.List<ParameterBinding> parameterBindings)static MethodReferenceforForgedMethod(Method method, java.util.List<ParameterBinding> parameterBindings)static MethodReferenceforMapperReference(Method method, MapperReference declaringMapper, java.util.List<ParameterBinding> parameterBindings)static MethodReferenceforMethodCall(java.lang.String methodName)static MethodReferenceforMethodChaining(MethodReference... references)static MethodReferenceforParameterProvidedMethod(Method method, Parameter providingParameter, java.util.List<ParameterBinding> parameterBindings)static MethodReferenceforStaticBuilder(java.lang.String builderCreationMethod, Type definingType)AssignmentgetAssignment()java.lang.StringgetContextParam()MapperReferencegetDeclaringMapper()TypegetDefiningType()java.util.Set<Type>getImportTypes()Returns a set containing thoseTypes referenced by this model element for which an import statement needs to be declared.java.lang.StringgetMapperVariableName()java.util.List<MethodReference>getMethodsToChain()java.lang.StringgetName()java.util.List<ParameterBinding>getParameterBindings()ParametergetProvidingParameter()TypegetReturnType()TypegetSingleSourceParameterType()java.lang.StringgetSourceLocalVarName()java.lang.StringgetSourceLoopVarName()SeeAssignment.getSourceLoopVarName()(java.lang.String) }java.lang.StringgetSourceParameterName()Returns the source parameter name, to which this assignment applies.java.util.List<Parameter>getSourceParameters()PresenceCheckgetSourcePresenceCheckerReference()the source presence checker referencejava.lang.StringgetSourceReference()the source reference being a source-getter, a constant, nested method call, etc.TypegetSourceType()the source type used in the matching processjava.util.List<Type>getThrownTypes()returns all types exception types thrown by this assignment.Assignment.AssignmentTypegetType()Returns whether the type of assignmentinthashCode()TypeinferTypeWhenEnum(Type type)booleanisCallingUpdateMethod()booleanisConstructor()booleanisMethodChaining()booleanisSourceReferenceParameter()booleanisStatic()voidsetAssignment(Assignment assignment)An assignment in itself can wrap another assignment.voidsetSourceLocalVarName(java.lang.String sourceLocalVarName)Replaces the sourceReference at the call site in the assignment in the template with this sourceLocalVarName.voidsetSourceLoopVarName(java.lang.String sourceLoopVarName)Replaces the sourceLocalVar or sourceReference at the call site in the assignment in the template with this sourceLoopVarName.java.lang.StringtoString()-
Methods inherited from class org.mapstruct.ap.internal.writer.FreeMarkerWritable
getTemplateName, getTemplateNameForClass, write
-
-
-
-
Field Detail
-
name
private final java.lang.String name
-
sourceParameters
private final java.util.List<Parameter> sourceParameters
-
returnType
private final Type returnType
-
declaringMapper
private final MapperReference declaringMapper
-
importTypes
private final java.util.Set<Type> importTypes
-
thrownTypes
private final java.util.List<Type> thrownTypes
-
isUpdateMethod
private final boolean isUpdateMethod
-
contextParam
private final java.lang.String contextParam
In case this reference targets a built-in method, allows to pass specific context information to the invoked method. Currently this is only used to pass in the configured date format string when invoking a built-in method which requires that.
-
assignment
private Assignment assignment
A reference to another mapping method or typeConversion in case this is a two-step mapping, e.g. fromJAXBElement<Bar>toFooto for which a nested method call will be generated:setFoo(barToFoo( jaxbElemToValue( bar) ) ). If there's no nested typeConversion or other mapping method, this will be a direct assignment.
-
definingType
private final Type definingType
-
parameterBindings
private final java.util.List<ParameterBinding> parameterBindings
-
providingParameter
private final Parameter providingParameter
-
methodsToChain
private final java.util.List<MethodReference> methodsToChain
-
isStatic
private final boolean isStatic
-
isConstructor
private final boolean isConstructor
-
isMethodChaining
private final boolean isMethodChaining
-
-
Constructor Detail
-
MethodReference
protected MethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, java.util.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
-
MethodReference
private MethodReference(BuiltInMethod method, ConversionContext contextParam)
-
MethodReference
private MethodReference(java.lang.String name, Type definingType, boolean isStatic)
-
MethodReference
private MethodReference(Type definingType, java.util.List<ParameterBinding> parameterBindings)
-
MethodReference
private MethodReference(MethodReference... references)
-
-
Method Detail
-
getDeclaringMapper
public MapperReference getDeclaringMapper()
-
getProvidingParameter
public Parameter getProvidingParameter()
-
getMapperVariableName
public java.lang.String getMapperVariableName()
-
getContextParam
public java.lang.String getContextParam()
-
getAssignment
public Assignment getAssignment()
-
getName
public java.lang.String getName()
-
getSourceParameters
public java.util.List<Parameter> getSourceParameters()
-
setAssignment
public void setAssignment(Assignment assignment)
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
public java.lang.String 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
public PresenceCheck getSourcePresenceCheckerReference()
Description copied from interface:Assignmentthe source presence checker reference- Specified by:
getSourcePresenceCheckerReferencein interfaceAssignment- Returns:
- source reference
-
getSourceType
public Type getSourceType()
Description copied from interface:Assignmentthe source type used in the matching process- Specified by:
getSourceTypein interfaceAssignment- Returns:
- source type (can be null)
-
createUniqueVarName
public java.lang.String createUniqueVarName(java.lang.String desiredName)
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
public java.lang.String getSourceLocalVarName()
Description copied from interface:Assignment- Specified by:
getSourceLocalVarNamein interfaceAssignment- Returns:
- local variable name (can be null if not set)
-
setSourceLocalVarName
public void setSourceLocalVarName(java.lang.String sourceLocalVarName)
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
public java.lang.String getSourceLoopVarName()
Description copied from interface:AssignmentSeeAssignment.getSourceLoopVarName()(java.lang.String) }- Specified by:
getSourceLoopVarNamein interfaceAssignment- Returns:
- loop variable (can be null if not set)
-
setSourceLoopVarName
public void setSourceLoopVarName(java.lang.String sourceLoopVarName)
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
public java.lang.String 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
public Type getSingleSourceParameterType()
- Returns:
- the type of the single source parameter that is not the
@TargetTypeparameter
-
getDefiningType
public Type getDefiningType()
-
getImportTypes
public java.util.Set<Type> 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
public java.util.List<Type> getThrownTypes()
Description copied from interface:Assignmentreturns all types exception types thrown by this assignment.- Specified by:
getThrownTypesin interfaceAssignment- Returns:
- exceptions thrown
-
getType
public Assignment.AssignmentType getType()
Description copied from interface:AssignmentReturns whether the type of assignment- Specified by:
getTypein interfaceAssignment- Returns:
Assignment.AssignmentType
-
getReturnType
public Type getReturnType()
-
isCallingUpdateMethod
public boolean isCallingUpdateMethod()
- Specified by:
isCallingUpdateMethodin interfaceAssignment
-
isStatic
public boolean isStatic()
-
isConstructor
public boolean isConstructor()
-
isMethodChaining
public boolean isMethodChaining()
-
getMethodsToChain
public java.util.List<MethodReference> getMethodsToChain()
-
getParameterBindings
public java.util.List<ParameterBinding> getParameterBindings()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
forBuiltInMethod
public static MethodReference forBuiltInMethod(BuiltInMethod method, ConversionContext contextParam)
-
forForgedMethod
public static MethodReference forForgedMethod(Method method, java.util.List<ParameterBinding> parameterBindings)
-
forParameterProvidedMethod
public static MethodReference forParameterProvidedMethod(Method method, Parameter providingParameter, java.util.List<ParameterBinding> parameterBindings)
-
forMapperReference
public static MethodReference forMapperReference(Method method, MapperReference declaringMapper, java.util.List<ParameterBinding> parameterBindings)
-
forStaticBuilder
public static MethodReference forStaticBuilder(java.lang.String builderCreationMethod, Type definingType)
-
forMethodCall
public static MethodReference forMethodCall(java.lang.String methodName)
-
forConstructorInvocation
public static MethodReference forConstructorInvocation(Type type, java.util.List<ParameterBinding> parameterBindings)
-
forMethodChaining
public static MethodReference forMethodChaining(MethodReference... references)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-