MappingCodeGenerator

class MappingCodeGenerator(logger: KSPLogger)

Generates per-field mapping expressions using KotlinPoet, dispatching on the scalar fallback ladder's landing shape:

  • LandingShape.HARD — non-null target without a usable default (ladder rows 1/5): the convertOrFail seam; absence and brokenness both surface as hard errors.

  • LandingShape.NULLABLE — nullable target (rows 3/7): convertOrNull (Auto) or convertOrNullStrict (OnFail.Throw); broken absorbs to null (reported) under Auto.

  • LandingShape.COPY — defaulted target built in the .copy() stage (rows 2/4/6/8): convertOrElse (Auto) or convertOrElseStrict with base.<field> as the fallback.

Path literals are the TARGET field name (single segment — nesting prefixes accumulate at runtime via MappingException.withPathPrefix; element seams append their own [i] / ["key"] segments); type literals are codegen string literals (fully-qualified for converter pairs and collection elements, simple class names for scalar nested mappers) so release builds stay readable under R8 without a mapping file.

Constructors

Link copied to clipboard
constructor(logger: KSPLogger)

Functions

Link copied to clipboard
fun generateFieldMapping(sourceField: FieldInfo, targetField: FieldInfo, strategy: MappingStrategy, isReverse: Boolean = false, inCopyStage: Boolean = false): CodeBlock