Structure
A TypeConverter has the following properties and functions.
Properties
-
val name: StringAll
TypeConvertermust have a (unique) name. It should also describe the mapping, e.g.StringToIntConverter. A list of providedTypeConverternames is generated and published in packageio.mcarle.konvert.api.converter. -
val enabledByDefault: BooleanNot all converters may be suitable for every use case: For example a conversion of a
Stringto anIntmay not always be possible. But sometimes, you exactly want to do that specific conversion and you enable it. -
val priority: IntUsed to sort all the available converters, as the first possible converter will be used. This enables to e.g. override a specific converter by defining a lower value here.
NoteLower values have higher priorities!
Functions
-
fun init(resolver: Resolver)Used to initialise all TypeConverters in the beginning of the KSP with the resolver.
-
fun matches(source: KSType, target: KSType): BooleanUsed to check, if this type converter is able to do the conversion from
sourcetotarget -
fun convert(fieldName: String, source: KSType, target: KSType): CodeBlockCalled to generate the kotlin code to convert the field
fieldNameof typesourceto typetarget.