
org.jetbrains.kotlin.gradle.idea.serialize.IdeaKotlinExtrasSerializationExtension.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.idea.serialize
import org.jetbrains.kotlin.tooling.core.Extras
/**
* Extension point used to transport [Extras] from the Gradle process into the IDE during Gradle sync.
* Entities inside the Kotlin Tooling might allow for adding extras. If those entities
* are also semantically present in the import process of IntelliJ, then extras added on the origin instances
* can be retained by registering this extension on the Kotlin Gradle Plugin as well as in IntelliJ.
*
* Extras that cannot find a serializer will not be imported into the IDE.
* Evolving the attached extras and the resulting compatibility requirements have to be handled
* inside the implementation of the given [IdeaKotlinExtrasSerializer]
*/
interface IdeaKotlinExtrasSerializationExtension {
fun serializer(key: Extras.Key): IdeaKotlinExtrasSerializer?
object Empty : IdeaKotlinExtrasSerializationExtension {
override fun serializer(key: Extras.Key): IdeaKotlinExtrasSerializer? = null
}
}
interface IdeaKotlinExtrasSerializationExtensionBuilder {
fun register(key: Extras.Key, serializer: IdeaKotlinExtrasSerializer)
}
fun IdeaKotlinExtrasSerializationExtension(
builder: IdeaKotlinExtrasSerializationExtensionBuilder.() -> Unit
): IdeaKotlinExtrasSerializationExtension {
return IdeaKotlinExtrasSerializationExtensionImpl(
IdeaKotlinExtrasSerializationExtensionBuilderImpl().apply(builder).serializers
)
}
private class IdeaKotlinExtrasSerializationExtensionBuilderImpl : IdeaKotlinExtrasSerializationExtensionBuilder {
val serializers = mutableMapOf, IdeaKotlinExtrasSerializer<*>>()
override fun register(key: Extras.Key, serializer: IdeaKotlinExtrasSerializer) {
serializers[key] = serializer
}
}
private class IdeaKotlinExtrasSerializationExtensionImpl(
private val map: Map, IdeaKotlinExtrasSerializer<*>>
) : IdeaKotlinExtrasSerializationExtension {
override fun serializer(key: Extras.Key): IdeaKotlinExtrasSerializer? {
@Suppress("unchecked_cast")
return map[key] as? IdeaKotlinExtrasSerializer
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy