From 8b4761880db51f26630b996fa6d2ddf5622bcff7 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Fri, 21 Jun 2024 09:51:44 +0200 Subject: [PATCH] Changed all explicit mapping functions to drop the mapped prefix --- .../io/github/mappie/resolving/Identifiers.kt | 8 ++++---- .../kotlin/io/github/mappie/api/EnumMappie.kt | 4 ++-- .../kotlin/io/github/mappie/api/ObjectMappie.kt | 14 +++++++------- .../io/github/mappie/api/TransformableValue.kt | 2 +- testing/src/main/kotlin/testing/ClassMapper.kt | 2 +- testing/src/main/kotlin/testing/ColorMapper.kt | 4 ++-- .../ConstructorParameterWhichIsNotAField.kt | 2 +- .../src/main/kotlin/testing/ExpressionMapper.kt | 4 ++-- testing/src/main/kotlin/testing/GameMapper.kt | 2 +- testing/src/main/kotlin/testing/ListMapper.kt | 4 ++-- .../main/kotlin/testing/MultipleConstructor.kt | 2 +- testing/src/main/kotlin/testing/NestedMapper.kt | 4 ++-- testing/src/main/kotlin/testing/PersonMapper.kt | 8 ++++---- .../main/kotlin/testing/PrivateConstructor.kt | 2 +- .../posts/enum-mapping/posts/entry-mapping.md | 4 ++-- .../posts/object-mapping/posts/collections.md | 2 +- .../src/posts/object-mapping/posts/resolving.md | 16 ++++++++-------- .../src/posts/object-mapping/posts/reusing.md | 2 +- .../posts/object-mapping/posts/transforming.md | 4 ++-- 19 files changed, 45 insertions(+), 45 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/io/github/mappie/resolving/Identifiers.kt b/compiler-plugin/src/main/kotlin/io/github/mappie/resolving/Identifiers.kt index 76c4519b..8567a4eb 100644 --- a/compiler-plugin/src/main/kotlin/io/github/mappie/resolving/Identifiers.kt +++ b/compiler-plugin/src/main/kotlin/io/github/mappie/resolving/Identifiers.kt @@ -10,13 +10,13 @@ val IDENTIFIER_MAP_LIST = Name.identifier("mapList") val IDENTIFIER_MAP_SET = Name.identifier("mapSet") -val IDENTIFIER_MAPPED_FROM_ENUM_ENTRY = Name.identifier("mappedFromEnumEntry") +val IDENTIFIER_MAPPED_FROM_ENUM_ENTRY = Name.identifier("fromEnumEntry") -val IDENTIFIER_MAPPED_FROM_PROPERTY = Name.identifier("mappedFromProperty") +val IDENTIFIER_MAPPED_FROM_PROPERTY = Name.identifier("fromProperty") -val IDENTIFIER_MAPPED_FROM_CONSTANT = Name.identifier("mappedFromConstant") +val IDENTIFIER_MAPPED_FROM_CONSTANT = Name.identifier("fromConstant") -val IDENTIFIER_MAPPED_FROM_EXPRESSION = Name.identifier("mappedFromExpression") +val IDENTIFIER_MAPPED_FROM_EXPRESSION = Name.identifier("fromExpression") val IDENTIFIER_PARAMETER = Name.identifier("parameter") diff --git a/mappie-api/src/commonMain/kotlin/io/github/mappie/api/EnumMappie.kt b/mappie-api/src/commonMain/kotlin/io/github/mappie/api/EnumMappie.kt index e348d7dd..2ac46665 100644 --- a/mappie-api/src/commonMain/kotlin/io/github/mappie/api/EnumMappie.kt +++ b/mappie-api/src/commonMain/kotlin/io/github/mappie/api/EnumMappie.kt @@ -24,9 +24,9 @@ public abstract class EnumMappie, TO : Enum<*>> : Mappie * * For example * ```kotlin - * Colour.UNKNOWN mappedFromEnumEntry Color.ORANGE + * Colour.UNKNOWN fromEnumEntry Color.ORANGE * ``` * will generate an explicit mapping, mapping `Colour.ORANGE` to `Color.UNKNOWN`. */ - protected infix fun TO.mappedFromEnumEntry(source: FROM): EnumMappie = generated() + protected infix fun TO.fromEnumEntry(source: FROM): EnumMappie = generated() } \ No newline at end of file diff --git a/mappie-api/src/commonMain/kotlin/io/github/mappie/api/ObjectMappie.kt b/mappie-api/src/commonMain/kotlin/io/github/mappie/api/ObjectMappie.kt index 8fb13172..80753b25 100644 --- a/mappie-api/src/commonMain/kotlin/io/github/mappie/api/ObjectMappie.kt +++ b/mappie-api/src/commonMain/kotlin/io/github/mappie/api/ObjectMappie.kt @@ -38,11 +38,11 @@ public abstract class ObjectMappie : Mappie() { * * For example * ```kotlin - * Person::name mappedFromProperty PersonDto::fullName + * Person::name fromProperty PersonDto::fullName * ``` * will generate an explicit mapping, setting constructor parameter `Person.name` to `PersonDto.fullName`. */ - protected infix fun KProperty1.mappedFromProperty(source: KProperty1): TransformableValue = + protected infix fun KProperty1.fromProperty(source: KProperty1): TransformableValue = generated() /** @@ -50,11 +50,11 @@ public abstract class ObjectMappie : Mappie() { * * For example * ```kotlin - * Person::name mappedFromConstant "John Doe" + * Person::name fromConstant "John Doe" * ``` * will generate an explicit mapping, setting constructor parameter `Person.name` to `"John Doe"`. */ - protected infix fun KProperty1.mappedFromConstant(value: TO_TYPE): Unit = + protected infix fun KProperty1.fromConstant(value: TO_TYPE): Unit = generated() /** @@ -62,12 +62,12 @@ public abstract class ObjectMappie : Mappie() { * * For example * ```kotlin - * Person::name mappedFromConstant { personDto -> personDto.fullName + " (full)" } + * Person::name fromConstant { personDto -> personDto.fullName + " (full)" } * ``` * will generate an explicit mapping, setting constructor parameter `Person.name` to `"John Doe (full)"`, * assuming `personDto.fullName == "John Doe"`. */ - protected infix fun KProperty1.mappedFromExpression(function: (FROM) -> TO_TYPE): Unit = + protected infix fun KProperty1.fromExpression(function: (FROM) -> TO_TYPE): Unit = generated() /** @@ -75,7 +75,7 @@ public abstract class ObjectMappie : Mappie() { * * For example * ```kotlin - * parameter("name") mappedFromProperty PersonDto::fullName + * parameter("name") fromProperty PersonDto::fullName * ``` * will generate an explicit mapping, setting constructor parameter `name` to `PersonDto.fullName`. */ diff --git a/mappie-api/src/commonMain/kotlin/io/github/mappie/api/TransformableValue.kt b/mappie-api/src/commonMain/kotlin/io/github/mappie/api/TransformableValue.kt index ca29b814..ed7cceb4 100644 --- a/mappie-api/src/commonMain/kotlin/io/github/mappie/api/TransformableValue.kt +++ b/mappie-api/src/commonMain/kotlin/io/github/mappie/api/TransformableValue.kt @@ -13,7 +13,7 @@ public class TransformableValue { * * For example * ```kotlin - * Person::age mappedFromProperty PersonDto::dateOfBirth transform { it.periodUntil(Clock.todayIn(TimeZone.UTC)) } + * Person::age fromProperty PersonDto::dateOfBirth transform { it.periodUntil(Clock.todayIn(TimeZone.UTC)) } * ``` * will generate an explicit mapping transforming `PersonDto.dateOfBirth` to the period between it and today. * diff --git a/testing/src/main/kotlin/testing/ClassMapper.kt b/testing/src/main/kotlin/testing/ClassMapper.kt index a3e5e5b0..e0b96c71 100644 --- a/testing/src/main/kotlin/testing/ClassMapper.kt +++ b/testing/src/main/kotlin/testing/ClassMapper.kt @@ -24,6 +24,6 @@ class ClassDto( object ClassMapper : ObjectMappie() { override fun map(from: Class) = mapping { - ClassDto::argument mappedFromConstant 1 + ClassDto::argument fromConstant 1 } } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/ColorMapper.kt b/testing/src/main/kotlin/testing/ColorMapper.kt index 6e1932f0..0c0af2eb 100644 --- a/testing/src/main/kotlin/testing/ColorMapper.kt +++ b/testing/src/main/kotlin/testing/ColorMapper.kt @@ -19,7 +19,7 @@ enum class Colour { object ColorMapper : EnumMappie() { override fun map(from: Color): Colour = mapping { - Colour.OTHER mappedFromEnumEntry Color.ORANGE - Colour.OTHER mappedFromEnumEntry Color.PURPLE + Colour.OTHER fromEnumEntry Color.ORANGE + Colour.OTHER fromEnumEntry Color.PURPLE } } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/ConstructorParameterWhichIsNotAField.kt b/testing/src/main/kotlin/testing/ConstructorParameterWhichIsNotAField.kt index 74461be3..bab0072d 100644 --- a/testing/src/main/kotlin/testing/ConstructorParameterWhichIsNotAField.kt +++ b/testing/src/main/kotlin/testing/ConstructorParameterWhichIsNotAField.kt @@ -24,6 +24,6 @@ class ConstructorParameterWhichIsNotAFieldDto( object ConstructorParameterWhichIsNotAFieldMapper : ObjectMappie() { override fun map(from: ConstructorParameterWhichIsNotAField): ConstructorParameterWhichIsNotAFieldDto = mapping { - parameter("value") mappedFromProperty ConstructorParameterWhichIsNotAField::parameter + parameter("value") fromProperty ConstructorParameterWhichIsNotAField::parameter } } diff --git a/testing/src/main/kotlin/testing/ExpressionMapper.kt b/testing/src/main/kotlin/testing/ExpressionMapper.kt index f91fa95f..d9dde206 100644 --- a/testing/src/main/kotlin/testing/ExpressionMapper.kt +++ b/testing/src/main/kotlin/testing/ExpressionMapper.kt @@ -4,7 +4,7 @@ import io.github.mappie.api.ObjectMappie object ExpressionMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::age mappedFromConstant 10 - PersonDto::description mappedFromExpression { it::class.simpleName!! } + PersonDto::age fromConstant 10 + PersonDto::description fromExpression { it::class.simpleName!! } } } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/GameMapper.kt b/testing/src/main/kotlin/testing/GameMapper.kt index c9267a86..53792bb7 100644 --- a/testing/src/main/kotlin/testing/GameMapper.kt +++ b/testing/src/main/kotlin/testing/GameMapper.kt @@ -14,6 +14,6 @@ data class GameDto( object GameMapper : ObjectMappie() { override fun map(from: Game): GameDto = mapping { - GameDto::description mappedFromProperty Game::description transform { it ?: "default" } + GameDto::description fromProperty Game::description transform { it ?: "default" } } } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/ListMapper.kt b/testing/src/main/kotlin/testing/ListMapper.kt index b693581e..b51c01d1 100644 --- a/testing/src/main/kotlin/testing/ListMapper.kt +++ b/testing/src/main/kotlin/testing/ListMapper.kt @@ -14,13 +14,13 @@ data class BookSetDto(val pages: Set) object BookListMapper : ObjectMappie() { override fun map(from: BookList): BookListDto = mapping { - BookListDto::pages mappedFromProperty BookList::pages via PageMapper.forList + BookListDto::pages fromProperty BookList::pages via PageMapper.forList } } object BookSetMapper : ObjectMappie() { override fun map(from: BookSet): BookSetDto = mapping { - BookSetDto::pages mappedFromProperty BookSet::pages via PageMapper.forSet + BookSetDto::pages fromProperty BookSet::pages via PageMapper.forSet } } diff --git a/testing/src/main/kotlin/testing/MultipleConstructor.kt b/testing/src/main/kotlin/testing/MultipleConstructor.kt index 30a9fcbd..8348c08c 100644 --- a/testing/src/main/kotlin/testing/MultipleConstructor.kt +++ b/testing/src/main/kotlin/testing/MultipleConstructor.kt @@ -14,6 +14,6 @@ object MultipleConstructorsWithoutIntMapper : ObjectMappie() { override fun map(from: MultipleConstructors): MultipleConstructorsDto = mapping { - MultipleConstructorsDto::int mappedFromConstant 2 + MultipleConstructorsDto::int fromConstant 2 } } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/NestedMapper.kt b/testing/src/main/kotlin/testing/NestedMapper.kt index 2fa329c6..cd49ca5d 100644 --- a/testing/src/main/kotlin/testing/NestedMapper.kt +++ b/testing/src/main/kotlin/testing/NestedMapper.kt @@ -23,8 +23,8 @@ data class ThangDto(val description: String) object ThingMapper : ObjectMappie() { override fun map(from: Thing): ThingDto = mapping { - ThingDto::inner mappedFromProperty Thing::inner via ThangMapper - ThingDto::boolean mappedFromProperty Thing::boolean via BooleanMapper() + ThingDto::inner fromProperty Thing::inner via ThangMapper + ThingDto::boolean fromProperty Thing::boolean via BooleanMapper() } } diff --git a/testing/src/main/kotlin/testing/PersonMapper.kt b/testing/src/main/kotlin/testing/PersonMapper.kt index 109ba3af..cc608702 100644 --- a/testing/src/main/kotlin/testing/PersonMapper.kt +++ b/testing/src/main/kotlin/testing/PersonMapper.kt @@ -10,8 +10,8 @@ data class PersonDto(val name: String, val description: String, val age: Int) object PersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::description mappedFromProperty Person::name - PersonDto::age mappedFromConstant 26 + PersonDto::description fromProperty Person::name + PersonDto::age fromConstant 26 } } @@ -26,7 +26,7 @@ object ConstructorCallPersonMapper : Mappie() { object TransformingPersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::description mappedFromProperty Person::name transform { "$it Surname" } - PersonDto::age mappedFromConstant 24 + PersonDto::description fromProperty Person::name transform { "$it Surname" } + PersonDto::age fromConstant 24 } } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/PrivateConstructor.kt b/testing/src/main/kotlin/testing/PrivateConstructor.kt index be428e18..faf9174b 100644 --- a/testing/src/main/kotlin/testing/PrivateConstructor.kt +++ b/testing/src/main/kotlin/testing/PrivateConstructor.kt @@ -10,6 +10,6 @@ data class PrivateConstructorDto constructor(val string: String, val int: Int) { object PrivateConstructorMapper : ObjectMappie() { override fun map(from: PrivateConstructor): PrivateConstructorDto = mapping { - PrivateConstructorDto::int mappedFromConstant 1 + PrivateConstructorDto::int fromConstant 1 } } \ No newline at end of file diff --git a/website/src/posts/enum-mapping/posts/entry-mapping.md b/website/src/posts/enum-mapping/posts/entry-mapping.md index 19afad9a..99af59f4 100644 --- a/website/src/posts/enum-mapping/posts/entry-mapping.md +++ b/website/src/posts/enum-mapping/posts/entry-mapping.md @@ -18,11 +18,11 @@ enum class Color { RED, GREEN, BLUE, ORANGE; } enum class Colour { RED, GREEN, BLUE, OTHER; } ``` -We can generate a complete mapper by mapping `Colour.ORANGE` to `Colour.OTHER` via `mappedFromEnumEntry` +We can generate a complete mapper by mapping `Colour.ORANGE` to `Colour.OTHER` via `fromEnumEntry` ```kotlin object ColorMapper : EnumMappie() { override fun map(from: Color): Colour = mapping { - Colour.OTHER mappedFromEnumEntry Color.ORANGE + Colour.OTHER fromEnumEntry Color.ORANGE } } ``` \ No newline at end of file diff --git a/website/src/posts/object-mapping/posts/collections.md b/website/src/posts/object-mapping/posts/collections.md index 854fad45..62b5745a 100644 --- a/website/src/posts/object-mapping/posts/collections.md +++ b/website/src/posts/object-mapping/posts/collections.md @@ -31,7 +31,7 @@ object PageMapper : ObjectMappie() { object BookMapper : ObjectMappie() { override fun map(from: Book): BookDto = mapping { - BookDto::pages mappedFromProperty Book::pages via PageMapper.forList + BookDto::pages fromProperty Book::pages via PageMapper.forList } } ``` \ No newline at end of file diff --git a/website/src/posts/object-mapping/posts/resolving.md b/website/src/posts/object-mapping/posts/resolving.md index 6ccb723a..fabf1d6b 100644 --- a/website/src/posts/object-mapping/posts/resolving.md +++ b/website/src/posts/object-mapping/posts/resolving.md @@ -27,12 +27,12 @@ When a mapping function is defined without any explicit mappings, Mappie will th 3. setting the target from an expression. ## Mapping via a Source Property -Targets can be set via the operator `mappedFromProperty`. This will set the target to the given source property. +Targets can be set via the operator `fromProperty`. This will set the target to the given source property. For example ```kotlin object PersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::description mappedFromProperty Person::name + PersonDto::description fromProperty Person::name } } ``` @@ -42,28 +42,28 @@ Sometimes, you want to map from a source property, but tweak the value, handle n some other way. See [Transforming](/object-mapping/transforming/) for some guidelines. ## Mapping via a Constant -Targets can be set via the operator `mappedFromConstant`. This will set the target to the given constant. +Targets can be set via the operator `fromConstant`. This will set the target to the given constant. For example ```kotlin object PersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::description mappedFromConstant "unknown" + PersonDto::description fromConstant "unknown" } } ``` will always set `PersonDto.description` to `"unknown`. ## Mapping via an Expression -Targets can be set via the operator `mappedFromExpression`. This will set the target to the given lambda result. +Targets can be set via the operator `fromExpression`. This will set the target to the given lambda result. -The difference between `mappedFromExpression` and `mappedFromConstant` is that `mappedFromExpression` will take a lambda +The difference between `fromExpression` and `fromConstant` is that `fromExpression` will take a lambda function as a parameter, which takes the original `source` as a parameter. Allowing for more flexibility. For example ```kotlin object PersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::description mappedFromExpression { from -> "Description: ${from.name}" } + PersonDto::description fromExpression { from -> "Description: ${from.name}" } } } ``` @@ -86,7 +86,7 @@ we can use `parameter("description")` to reference the constructor parameter ```kotlin object PersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - parameter("description") mappedFromConstant "a constant" + parameter("description") fromConstant "a constant" } } ``` \ No newline at end of file diff --git a/website/src/posts/object-mapping/posts/reusing.md b/website/src/posts/object-mapping/posts/reusing.md index 16a3376a..0a5a1f99 100644 --- a/website/src/posts/object-mapping/posts/reusing.md +++ b/website/src/posts/object-mapping/posts/reusing.md @@ -43,7 +43,7 @@ the operator `via` ```kotlin object PersonMapper : ObjectMappie() { override fun map(from: Address) = mapping { - PersonDto::address mappedFromProperty PersonDto::address via AddressMapper + PersonDto::address fromProperty PersonDto::address via AddressMapper } } ``` diff --git a/website/src/posts/object-mapping/posts/transforming.md b/website/src/posts/object-mapping/posts/transforming.md index 61300e1c..c8651912 100644 --- a/website/src/posts/object-mapping/posts/transforming.md +++ b/website/src/posts/object-mapping/posts/transforming.md @@ -25,7 +25,7 @@ we can create a mapper between `Person` and `PersonDto` via ```kotlin object PersonMapper : ObjectMappie() { override fun map(from: Person): PersonDto = mapping { - PersonDto::age mappedFromProperty Person::dateOfBirth transform { dateOfBirth -> + PersonDto::age fromProperty Person::dateOfBirth transform { dateOfBirth -> Clock.todayIn(TimeZone.currentSystemDefault()).periodUntil(dateOfBirth) } } @@ -48,7 +48,7 @@ We create a mapping between `Dog` and `DogDto` via ```kotlin object DogMapper : ObjectMappie() { override fun map(from: Dog): DogDto = mapping { - DogDto::name mappedFromProperty DogDto::name transform { + DogDto::name fromProperty DogDto::name transform { it ?: "unknown" } }