Class 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 the new operator).
    • Field Detail

      • name

        private final java.lang.String name
      • sourceParameters

        private final java.util.List<Parameter> sourceParameters
      • returnType

        private final Type returnType
      • 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. from JAXBElement<Bar> to Foo to 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 reference
        declaringMapper - the method declaring the mapper; null if the current mapper itself
        providingParameter - The parameter providing the mapper, or null if the method is defined by the mapper itself or by declaringMapper.
        parameterBindings - the parameter bindings of this method reference
      • 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

      • 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: 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 interface Assignment
        Parameters:
        assignment - the assignment to set
      • getSourceReference

        public java.lang.String getSourceReference()
        Description copied from interface: Assignment
        the source reference being a source-getter, a constant, nested method call, etc.
        Specified by:
        getSourceReference in interface Assignment
        Returns:
        source reference
      • getSourceType

        public Type getSourceType()
        Description copied from interface: Assignment
        the source type used in the matching process
        Specified by:
        getSourceType in interface Assignment
        Returns:
        source type (can be null)
      • createUniqueVarName

        public java.lang.String createUniqueVarName​(java.lang.String desiredName)
        Description copied from interface: Assignment
        Creates an unique safe (local) variable name.
        Specified by:
        createUniqueVarName in interface Assignment
        Parameters:
        desiredName - the desired name
        Returns:
        the desired name, made unique in the scope of the bean mapping.
      • setSourceLocalVarName

        public void setSourceLocalVarName​(java.lang.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 interface Assignment
        Parameters:
        sourceLocalVarName - source local variable name
      • setSourceLoopVarName

        public void setSourceLoopVarName​(java.lang.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 interface Assignment
        Parameters:
        sourceLoopVarName - loop variable
      • getSourceParameterName

        public java.lang.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 interface Assignment
        Returns:
        the source parameter name
      • isSourceReferenceParameter

        public boolean isSourceReferenceParameter()
        Specified by:
        isSourceReferenceParameter in interface Assignment
        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 java.util.Set<Type> getImportTypes()
        Description copied from class: ModelElement
        Returns a set containing those Types referenced by this model element for which an import statement needs to be declared.
        Specified by:
        getImportTypes in interface Assignment
        Specified by:
        getImportTypes in class ModelElement
        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: Assignment
        returns all types exception types thrown by this assignment.
        Specified by:
        getThrownTypes in interface Assignment
        Returns:
        exceptions thrown
      • getReturnType

        public Type getReturnType()
      • 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()
      • inferTypeWhenEnum

        public Type inferTypeWhenEnum​(Type type)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • forStaticBuilder

        public static MethodReference forStaticBuilder​(java.lang.String builderCreationMethod,
                                                       Type definingType)
      • forMethodCall

        public static MethodReference forMethodCall​(java.lang.String methodName)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object