TypeMatcher

class TypeMatcher(logger: KSPLogger, customConverters: Map<Pair<String, String>, String> = emptyMap(), collectionWrappers: Map<String, CollectionWrapperDescriptor> = emptyMap(), introspector: ConverterIntrospector? = null)

Determines the appropriate mapping strategy for field transformations.

Converter resolution is pair-keyed and orientation-aware: per-field use= override (from @ConvertWith / @ConvertTo / @ConvertFrom) > @KMapperConfig custom registry (pair, either orientation) > built-in registry (pair, either orientation). Policy-only directives (onFail without use) never short-circuit discovery. A resolved pair whose needed direction is not provided → UnsupportedConversion compile error; no pair at all → MissingConverter compile error.

Parameters

customConverters

Map of (sourceFqn to targetFqn) → converterFqn, populated from @KMapperConfig.

collectionWrappers

Map of wrapped-collection-FQN → validated wrapper descriptor (object FQN + provided wrap/unwrap directions), from @CollectionWrapper discovery.

introspector

Reads converter shapes (type pair + provided directions); null disables shape-aware resolution (every converter reference then errors as missing — tests only).

Constructors

Link copied to clipboard
constructor(logger: KSPLogger, customConverters: Map<Pair<String, String>, String> = emptyMap(), collectionWrappers: Map<String, CollectionWrapperDescriptor> = emptyMap(), introspector: ConverterIntrospector? = null)

Functions

Link copied to clipboard
fun determineMappingStrategy(sourceField: FieldInfo, targetField: FieldInfo, isReverse: Boolean = false): MappingStrategy

Entry point per (sourceField, targetField) pair: runs field-level compile-time preconditions once, then resolves the strategy. Element-level recursion (collections, maps) bypasses the preconditions so they fire once per field, not per recursion step.

Link copied to clipboard
fun extractCollectionElementType(type: KSType): KSType?
Link copied to clipboard
fun extractMapKeyType(type: KSType): KSType?
Link copied to clipboard
fun extractMapValueType(type: KSType): KSType?
Link copied to clipboard
fun isCollectionType(type: KSType): Boolean
Link copied to clipboard
fun isMapType(type: KSType): Boolean
Link copied to clipboard
fun isStdlibCollectionType(type: KSType): Boolean

Returns true for the plain stdlib collection containers (List/MutableList/Set/MutableSet) only — excludes wrapped types like kotlinx.collections.immutable. Used as the unwrap direction's TARGET shape check: unwrap() lands on a plain collection by contract.