com.google.devtools.ksp.common.PersistentMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of symbol-processing-cmdline Show documentation
Show all versions of symbol-processing-cmdline Show documentation
Symbol processing for K/N and command line
package com.google.devtools.ksp.common
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import kotlinx.serialization.json.encodeToStream
import java.io.BufferedInputStream
import java.io.File
private object FileSerializer : KSerializer {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("File", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: File) = encoder.encodeString(value.path)
override fun deserialize(decoder: Decoder): File = File(decoder.decodeString())
}
private object SymbolSerializer : KSerializer {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("LookupSymbolWrapper", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: LookupSymbolWrapper) =
encoder.encodeString("${value.name}:${value.scope}")
override fun deserialize(decoder: Decoder): LookupSymbolWrapper {
val (name, scope) = decoder.decodeString().split(':')
return LookupSymbolWrapper(name, scope)
}
}
private val fileToFilesMapSerializer = MapSerializer(FileSerializer, ListSerializer(FileSerializer))
private val fileToSymbolsMapSerializer = MapSerializer(FileSerializer, ListSerializer(SymbolSerializer))
abstract class PersistentMap(
private val serializer: KSerializer
© 2015 - 2024 Weber Informatics LLC | Privacy Policy