diff --git a/shapeshift/src/main/kotlin/dev/krud/shapeshift/ShapeShift.kt b/shapeshift/src/main/kotlin/dev/krud/shapeshift/ShapeShift.kt index ce08662..68653a8 100644 --- a/shapeshift/src/main/kotlin/dev/krud/shapeshift/ShapeShift.kt +++ b/shapeshift/src/main/kotlin/dev/krud/shapeshift/ShapeShift.kt @@ -79,7 +79,7 @@ class ShapeShift internal constructor( val decorators = getDecorators(classPair) if (decorators.isNotEmpty()) { - val context = MappingDecoratorContext(fromObject, toObject) + val context = MappingDecoratorContext(fromObject, toObject, this) for (decorator in decorators) { decorator.decorate(context) } @@ -139,7 +139,7 @@ class ShapeShift internal constructor( if (condition != null) { condition as MappingCondition - val context = MappingConditionContext(fromValue) + val context = MappingConditionContext(fromValue, this) if (!condition.isValid(context)) { return } @@ -147,11 +147,11 @@ class ShapeShift internal constructor( val valueToSet = if (resolvedMappedField.transformer != null) { val transformer = resolvedMappedField.transformer as MappingTransformer - val context = MappingTransformerContext(fromValue, fromObject, toObject, fromPair.field, toPair.field) + val context = MappingTransformerContext(fromValue, fromObject, toObject, fromPair.field, toPair.field, this) transformer.transform(context) } else if (transformerRegistration != MappingTransformerRegistration.EMPTY) { val transformer = transformerRegistration.transformer as MappingTransformer - val context = MappingTransformerContext(fromValue, fromObject, toObject, fromPair.field, toPair.field) + val context = MappingTransformerContext(fromValue, fromObject, toObject, fromPair.field, toPair.field, this) transformer.transform(context) } else { fromValue diff --git a/shapeshift/src/main/kotlin/dev/krud/shapeshift/condition/MappingConditionContext.kt b/shapeshift/src/main/kotlin/dev/krud/shapeshift/condition/MappingConditionContext.kt index c897924..977188a 100644 --- a/shapeshift/src/main/kotlin/dev/krud/shapeshift/condition/MappingConditionContext.kt +++ b/shapeshift/src/main/kotlin/dev/krud/shapeshift/condition/MappingConditionContext.kt @@ -10,6 +10,8 @@ package dev.krud.shapeshift.condition +import dev.krud.shapeshift.ShapeShift + /** * The context payload used for [MappingCondition] */ @@ -17,5 +19,9 @@ data class MappingConditionContext( /** * The value to be mapped */ - val originalValue: Value? + val originalValue: Value?, + /** + * The [ShapeShift] instance used + */ + val shapeShift: ShapeShift ) \ No newline at end of file diff --git a/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/MappingDecoratorContext.kt b/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/MappingDecoratorContext.kt index 9d01138..ae0e1bd 100644 --- a/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/MappingDecoratorContext.kt +++ b/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/MappingDecoratorContext.kt @@ -10,6 +10,8 @@ package dev.krud.shapeshift.decorator +import dev.krud.shapeshift.ShapeShift + /** * The context payload used for [MappingDecorator] */ @@ -21,5 +23,9 @@ data class MappingDecoratorContext( /** * The to (target) object of the mapping */ - val to: To + val to: To, + /** + * The [ShapeShift] instance used + */ + val shapeShift: ShapeShift ) \ No newline at end of file diff --git a/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/base/MappingTransformerContext.kt b/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/base/MappingTransformerContext.kt index 892bc26..e4435e9 100644 --- a/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/base/MappingTransformerContext.kt +++ b/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/base/MappingTransformerContext.kt @@ -10,6 +10,7 @@ package dev.krud.shapeshift.transformer.base +import dev.krud.shapeshift.ShapeShift import java.lang.reflect.Field data class MappingTransformerContext( @@ -17,5 +18,6 @@ data class MappingTransformerContext( val fromObject: Any, val toObject: Any, val fromField: Field, - val toField: Field + val toField: Field, + val shapeShift: ShapeShift ) \ No newline at end of file diff --git a/shapeshift/src/test/kotlin/dev/krud/shapeshift/transformer/_fixtures.kt b/shapeshift/src/test/kotlin/dev/krud/shapeshift/transformer/_fixtures.kt index 6badfdc..e0e7e40 100644 --- a/shapeshift/src/test/kotlin/dev/krud/shapeshift/transformer/_fixtures.kt +++ b/shapeshift/src/test/kotlin/dev/krud/shapeshift/transformer/_fixtures.kt @@ -10,6 +10,7 @@ package dev.krud.shapeshift.transformer +import dev.krud.shapeshift.ShapeShiftBuilder import dev.krud.shapeshift.transformer.base.MappingTransformerContext import kotlin.reflect.jvm.javaField @@ -23,6 +24,7 @@ fun mockMappingTransformerContext(value: From?): MappingTransforme ExampleObject(), ExampleObject(), ExampleObject::name.javaField!!, - ExampleObject::name.javaField!! + ExampleObject::name.javaField!!, + ShapeShiftBuilder().build() ) } \ No newline at end of file