[Serialization] Reorganize module structure
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
description = "Kotlin Serialization Compiler Plugin (CLI)"
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":compiler:util"))
|
||||
compileOnly(project(":compiler:cli"))
|
||||
compileOnly(project(":compiler:plugin-api"))
|
||||
compileOnly(project(":compiler:fir:entrypoint"))
|
||||
|
||||
implementation(project(":kotlinx-serialization-compiler-plugin.common"))
|
||||
implementation(project(":kotlinx-serialization-compiler-plugin.k1"))
|
||||
implementation(project(":kotlinx-serialization-compiler-plugin.k2"))
|
||||
implementation(project(":kotlinx-serialization-compiler-plugin.backend"))
|
||||
|
||||
compileOnly(intellijCore())
|
||||
}
|
||||
|
||||
optInToExperimentalCompilerApi()
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { none() }
|
||||
}
|
||||
|
||||
runtimeJar()
|
||||
sourcesJar()
|
||||
javadocJar()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright 2010-2017 JetBrains s.r.o.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationComponentRegistrar
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.kotlinx.serialization.compiler.extensions
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||
import org.jetbrains.kotlin.js.translate.extensions.JsSyntheticTranslateExtension
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
|
||||
import org.jetbrains.kotlin.serialization.DescriptorSerializerPlugin
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.SerializationPluginDeclarationChecker
|
||||
|
||||
class SerializationComponentRegistrar : CompilerPluginRegistrar() {
|
||||
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
|
||||
Companion.registerExtensions(this)
|
||||
}
|
||||
|
||||
override val supportsK2: Boolean
|
||||
get() = false
|
||||
|
||||
companion object {
|
||||
fun registerExtensions(extensionStorage: ExtensionStorage) = with(extensionStorage) {
|
||||
// This method is never called in the IDE, therefore this extension is not available there.
|
||||
// Since IDE does not perform any serialization of descriptors, metadata written to the 'serializationDescriptorSerializer'
|
||||
// is never deleted, effectively causing memory leaks.
|
||||
// So we create SerializationDescriptorSerializerPlugin only outside of IDE.
|
||||
val serializationDescriptorSerializer = SerializationDescriptorSerializerPlugin()
|
||||
DescriptorSerializerPlugin.registerExtension(serializationDescriptorSerializer)
|
||||
registerProtoExtensions()
|
||||
|
||||
SyntheticResolveExtension.registerExtension(SerializationResolveExtension(serializationDescriptorSerializer))
|
||||
|
||||
ExpressionCodegenExtension.registerExtension(SerializationCodegenExtension(serializationDescriptorSerializer))
|
||||
JsSyntheticTranslateExtension.registerExtension(SerializationJsExtension(serializationDescriptorSerializer))
|
||||
IrGenerationExtension.registerExtension(SerializationLoweringExtension(serializationDescriptorSerializer))
|
||||
|
||||
StorageComponentContainerContributor.registerExtension(SerializationPluginComponentContainerContributor())
|
||||
}
|
||||
|
||||
private fun registerProtoExtensions() {
|
||||
SerializationPluginMetadataExtensions.registerAllExtensions(JvmProtoBufUtil.EXTENSION_REGISTRY)
|
||||
SerializationPluginMetadataExtensions.registerAllExtensions(JsSerializerProtocol.extensionRegistry)
|
||||
SerializationPluginMetadataExtensions.registerAllExtensions(KlibMetadataSerializerProtocol.extensionRegistry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SerializationPluginComponentContainerContributor : StorageComponentContainerContributor {
|
||||
override fun registerModuleComponents(
|
||||
container: StorageComponentContainer,
|
||||
platform: TargetPlatform,
|
||||
moduleDescriptor: ModuleDescriptor
|
||||
) {
|
||||
container.useInstance(SerializationPluginDeclarationChecker())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user