[KAPT4] Create basic infrastructure for KAPT4
This commit is contained in:
committed by
Space Team
parent
fc57f48c8f
commit
083f54aceb
+2
@@ -76,6 +76,7 @@ import org.jetbrains.kotlin.extensions.*
|
||||
import org.jetbrains.kotlin.extensions.internal.CandidateInterceptor
|
||||
import org.jetbrains.kotlin.extensions.internal.InternalNonStableExtensionPoints
|
||||
import org.jetbrains.kotlin.extensions.internal.TypeResolutionInterceptor
|
||||
import org.jetbrains.kotlin.fir.extensions.FirAnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.js.translate.extensions.JsSyntheticTranslateExtension
|
||||
@@ -673,6 +674,7 @@ class KotlinCoreEnvironment private constructor(
|
||||
FirExtensionRegistrarAdapter.registerExtensionPoint(project)
|
||||
TypeAttributeTranslatorExtension.registerExtensionPoint(project)
|
||||
AssignResolutionAltererExtension.registerExtensionPoint(project)
|
||||
FirAnalysisHandlerExtension.registerExtensionPoint(project)
|
||||
}
|
||||
|
||||
internal fun registerExtensionsFromPlugins(project: MockProject, configuration: CompilerConfiguration) {
|
||||
|
||||
+1
@@ -78,6 +78,7 @@ fun copyK2JVMCompilerArguments(from: K2JVMCompilerArguments, to: K2JVMCompilerAr
|
||||
to.typeEnhancementImprovementsInStrictMode = from.typeEnhancementImprovementsInStrictMode
|
||||
to.useFastJarFileSystem = from.useFastJarFileSystem
|
||||
to.useJavac = from.useJavac
|
||||
to.useKapt4 = from.useKapt4
|
||||
to.useOldBackend = from.useOldBackend
|
||||
to.useOldClassFilesReading = from.useOldClassFilesReading
|
||||
to.useOldInlineClassesManglingScheme = from.useOldInlineClassesManglingScheme
|
||||
|
||||
+9
@@ -846,6 +846,15 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
|
||||
field = value
|
||||
}
|
||||
|
||||
@Argument(
|
||||
value = "-Xuse-kapt4",
|
||||
description = "Enable the experimental KAPT 4."
|
||||
)
|
||||
var useKapt4 = false
|
||||
set(value) {
|
||||
checkFrozen()
|
||||
field = value
|
||||
}
|
||||
|
||||
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
||||
val result = super.configureAnalysisFlags(collector, languageVersion)
|
||||
|
||||
@@ -56,17 +56,18 @@ fun CompilerConfiguration.setupCommonArguments(
|
||||
buildHmppModuleStructure(arguments)?.let { put(CommonConfigurationKeys.HMPP_MODULE_STRUCTURE, it) }
|
||||
}
|
||||
|
||||
fun switchToFallbackModeIfNecessary(arguments: CommonCompilerArguments, messageCollector: MessageCollector) {
|
||||
val isK2 = arguments.useK2 || (arguments.languageVersion?.startsWith('2') ?: (LanguageVersion.LATEST_STABLE >= LanguageVersion.KOTLIN_2_0))
|
||||
if (isK2) {
|
||||
val isKaptUsed = arguments.pluginOptions?.any { it.startsWith("plugin:org.jetbrains.kotlin.kapt3") } == true
|
||||
if (isKaptUsed) {
|
||||
if (!arguments.suppressVersionWarnings) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"Kapt currently doesn't support language version 2.0+.\nFalling back to 1.9."
|
||||
)
|
||||
}
|
||||
private fun switchToFallbackModeIfNecessary(arguments: CommonCompilerArguments, messageCollector: MessageCollector) {
|
||||
fun warn(message: String) {
|
||||
if (!arguments.suppressVersionWarnings) messageCollector.report(CompilerMessageSeverity.STRONG_WARNING, message)
|
||||
}
|
||||
|
||||
if (arguments !is K2JVMCompilerArguments) return
|
||||
val isK2 =
|
||||
arguments.useK2 || (arguments.languageVersion?.startsWith('2') ?: (LanguageVersion.LATEST_STABLE >= LanguageVersion.KOTLIN_2_0))
|
||||
val isKaptUsed = arguments.pluginOptions?.any { it.startsWith("plugin:org.jetbrains.kotlin.kapt3") } == true
|
||||
when {
|
||||
isK2 && isKaptUsed && !arguments.useKapt4 -> {
|
||||
warn("Kapt currently doesn't support language version 2.0+. Falling back to 1.9.")
|
||||
arguments.languageVersion = LanguageVersion.KOTLIN_1_9.versionString
|
||||
if (arguments.apiVersion?.startsWith("2") == true) {
|
||||
arguments.apiVersion = ApiVersion.KOTLIN_1_9.versionString
|
||||
@@ -74,8 +75,11 @@ fun switchToFallbackModeIfNecessary(arguments: CommonCompilerArguments, messageC
|
||||
arguments.useK2 = false
|
||||
arguments.skipMetadataVersionCheck = true
|
||||
arguments.skipPrereleaseCheck = true
|
||||
(arguments as? K2JVMCompilerArguments)?.allowUnstableDependencies = true
|
||||
arguments.allowUnstableDependencies = true
|
||||
}
|
||||
isK2 && isKaptUsed && arguments.useKapt4 -> warn("Kapt 4 is still experimental. Use with caution.")
|
||||
arguments.useKapt4 && !isK2 -> warn("-Xuse-kapt4 flag can be only used with language version 2.0+.")
|
||||
arguments.useKapt4 && !isKaptUsed -> warn("-Xuse-kapt4 flag is present but no Kapt configuration options are provided.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user