diff --git a/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformedNamesComparison.scala b/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformedNamesComparison.scala index 16844af95..3669408db 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformedNamesComparison.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformedNamesComparison.scala @@ -1,13 +1,26 @@ package io.scalaland.chimney.dsl -// TODO: documentation - +/** Provides a way of customizing how fields/subtypes shoud get matched betwen source value and target value. + * + * @see [[https://chimney.readthedocs.io/supported-transformations/#defining-custom-name-matching-predicate]] for more details + * + * @since 1.0.0 + */ abstract class TransformedNamesComparison { this: Singleton => + /** Return true if `fromName` should be considered a match for `toName`. + * + * @param fromName name of a field/subtype in the source type + * @param toName name of a field/subtype in the target type + * @return whether fromName should be used as a source for value in toName + */ def namesMatch(fromName: String, toName: String): Boolean } + +/** @since 1.0.0 */ object TransformedNamesComparison { + /** Matches names, dropping is/get/set prefixes and then lowercasing the first letter if it was a Bean name. */ case object BeanAware extends TransformedNamesComparison { // While it's bad to refer to compiletime package this code should only be used by this compiletime package. @@ -19,11 +32,13 @@ object TransformedNamesComparison { fromName == toName || normalize(fromName) == normalize(toName) } + /** Matches only the same Strings. */ case object StrictEquality extends TransformedNamesComparison { def namesMatch(fromName: String, toName: String): Boolean = fromName == toName } + /** Matches Strings ignoring upper/lower case distinction. */ case object CaseInsensitiveEquality extends TransformedNamesComparison { def namesMatch(fromName: String, toName: String): Boolean = fromName.equalsIgnoreCase(toName) diff --git a/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformerFlagsDsl.scala b/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformerFlagsDsl.scala index ccb676b12..38532f3c9 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformerFlagsDsl.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/dsl/TransformerFlagsDsl.scala @@ -200,7 +200,7 @@ private[dsl] trait TransformerFlagsDsl[UpdateFlag[_ <: TransformerFlags], Flags * * @param namesComparison parameter specifying how names should be compared by macro * - * @see [[https://chimney.readthedocs.io/supported-transformations/#TODO]] for more details + * @see [[https://chimney.readthedocs.io/supported-transformations/#customizing-field-name-matching]] for more details * * @since 1.0.0 */ @@ -211,7 +211,7 @@ private[dsl] trait TransformerFlagsDsl[UpdateFlag[_ <: TransformerFlags], Flags /** Disable any custom way of comparing if source fields' names and target fields' names are matching. * - * @see [[https://chimney.readthedocs.io/supported-transformations/#TODO]] for more details + * @see [[https://chimney.readthedocs.io/supported-transformations/#customizing-field-name-matching]] for more details * * @since 1.0.0 */ @@ -222,7 +222,7 @@ private[dsl] trait TransformerFlagsDsl[UpdateFlag[_ <: TransformerFlags], Flags * * @param namesComparison parameter specifying how names should be compared by macro * - * @see [[https://chimney.readthedocs.io/supported-transformations/#TODO]] for more details + * @see [[https://chimney.readthedocs.io/supported-transformations/#customizing-subtype-name-matching]] for more details * * @since 1.0.0 */ @@ -233,7 +233,7 @@ private[dsl] trait TransformerFlagsDsl[UpdateFlag[_ <: TransformerFlags], Flags /** Disable any custom way of comparing if source subtypes' names and target fields' names are matching. * - * @see [[https://chimney.readthedocs.io/supported-transformations/#TODO]] for more details + * @see [[https://chimney.readthedocs.io/supported-transformations/#customizing-subtype-name-matching]] for more details * * @since 1.0.0 */