[AllOpen] Reorganize module structure of AllOpen plugin
This scheme will be common for all compiler plugins with K1 and K2 support: - `plugin-common` contains classes shared with K1 and K2 implementations (if any) - `plugin-k1` contains implementation for K1 compiler - `plugin-k2` contains implementation for K2 compiler - `plugin-backend` contains implementation for backend extensions (if any) - `plugin-cli` is module for registration of plugin in CLI compiler - `plugin` is a root module with tests and all submodules embedded This structure is needed to distinguish parts related to different frontends, which is needed for proper dependencies settings for Kotlin IDE plugins
This commit is contained in:
committed by
teamcity
parent
22ebea8174
commit
2a7dc1cc0c
@@ -0,0 +1,33 @@
|
||||
description = "Kotlin AllOpen Compiler Plugin (CLI)"
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":kotlin-allopen-compiler-plugin.k1"))
|
||||
implementation(project(":kotlin-allopen-compiler-plugin.k2"))
|
||||
compileOnly(project(":compiler:plugin-api"))
|
||||
compileOnly(project(":compiler:frontend"))
|
||||
|
||||
compileOnly(project(":compiler:fir:cones"))
|
||||
compileOnly(project(":compiler:fir:tree"))
|
||||
compileOnly(project(":compiler:fir:resolve"))
|
||||
compileOnly(project(":compiler:fir:checkers"))
|
||||
compileOnly(project(":compiler:ir.backend.common"))
|
||||
compileOnly(project(":compiler:fir:entrypoint"))
|
||||
|
||||
compileOnly(intellijCore())
|
||||
|
||||
runtimeOnly(kotlinStdlib())
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { none() }
|
||||
}
|
||||
|
||||
runtimeJar()
|
||||
sourcesJar()
|
||||
javadocJar()
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.allopen.AllOpenComponentRegistrar
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.allopen
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor.Companion.SUPPORTED_PRESETS
|
||||
import org.jetbrains.kotlin.allopen.AllOpenConfigurationKeys.ANNOTATION
|
||||
import org.jetbrains.kotlin.allopen.AllOpenConfigurationKeys.PRESET
|
||||
import org.jetbrains.kotlin.allopen.fir.FirAllOpenExtensionRegistrar
|
||||
import org.jetbrains.kotlin.compiler.plugin.*
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
|
||||
|
||||
object AllOpenConfigurationKeys {
|
||||
val ANNOTATION: CompilerConfigurationKey<List<String>> = CompilerConfigurationKey.create("annotation qualified name")
|
||||
val PRESET: CompilerConfigurationKey<List<String>> = CompilerConfigurationKey.create("annotation preset")
|
||||
}
|
||||
|
||||
class AllOpenCommandLineProcessor : CommandLineProcessor {
|
||||
companion object {
|
||||
val SUPPORTED_PRESETS = mapOf(
|
||||
"spring" to listOf(
|
||||
"org.springframework.stereotype.Component",
|
||||
"org.springframework.transaction.annotation.Transactional",
|
||||
"org.springframework.scheduling.annotation.Async",
|
||||
"org.springframework.cache.annotation.Cacheable",
|
||||
"org.springframework.boot.test.context.SpringBootTest",
|
||||
"org.springframework.validation.annotation.Validated"
|
||||
),
|
||||
"quarkus" to listOf(
|
||||
"javax.enterprise.context.ApplicationScoped",
|
||||
"javax.enterprise.context.RequestScoped"
|
||||
),
|
||||
"micronaut" to listOf(
|
||||
"io.micronaut.aop.Around",
|
||||
"io.micronaut.aop.Introduction",
|
||||
"io.micronaut.aop.InterceptorBinding",
|
||||
"io.micronaut.aop.InterceptorBindingDefinitions"
|
||||
)
|
||||
)
|
||||
|
||||
val ANNOTATION_OPTION = CliOption(
|
||||
"annotation", "<fqname>", "Annotation qualified names",
|
||||
required = false, allowMultipleOccurrences = true
|
||||
)
|
||||
|
||||
val PRESET_OPTION = CliOption(
|
||||
"preset", "<name>", "Preset name (${SUPPORTED_PRESETS.keys.joinToString()})",
|
||||
required = false, allowMultipleOccurrences = true
|
||||
)
|
||||
|
||||
const val PLUGIN_ID = "org.jetbrains.kotlin.allopen"
|
||||
}
|
||||
|
||||
override val pluginId = PLUGIN_ID
|
||||
override val pluginOptions = listOf(ANNOTATION_OPTION, PRESET_OPTION)
|
||||
|
||||
override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) = when (option) {
|
||||
ANNOTATION_OPTION -> configuration.appendList(ANNOTATION, value)
|
||||
PRESET_OPTION -> configuration.appendList(PRESET, value)
|
||||
else -> throw CliOptionProcessingException("Unknown option: ${option.optionName}")
|
||||
}
|
||||
}
|
||||
|
||||
class AllOpenComponentRegistrar : ComponentRegistrar {
|
||||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
|
||||
val annotations = configuration.get(ANNOTATION)?.toMutableList() ?: mutableListOf()
|
||||
configuration.get(PRESET)?.forEach { preset ->
|
||||
SUPPORTED_PRESETS[preset]?.let { annotations += it }
|
||||
}
|
||||
if (annotations.isEmpty()) return
|
||||
|
||||
DeclarationAttributeAltererExtension.registerExtension(project, CliAllOpenDeclarationAttributeAltererExtension(annotations))
|
||||
FirExtensionRegistrar.registerExtension(project, FirAllOpenExtensionRegistrar(annotations))
|
||||
}
|
||||
|
||||
override val supportsK2: Boolean
|
||||
get() = true
|
||||
}
|
||||
Reference in New Issue
Block a user