Skip to content

Commit

Permalink
Scaladoc documentation for name matching customization
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Mar 24, 2024
1 parent 9beb1cf commit 68380c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down

0 comments on commit 68380c2

Please sign in to comment.