1- @file:Suppress(" DEPRECATION" , " DEPRECATION_ERROR" )
2- @file:OptIn(ExperimentalCompilerApi ::class )
3-
41package com.github.codeql
52
63import com.intellij.mock.MockProject
4+ import com.intellij.openapi.extensions.LoadingOrder
75import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
86import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
97import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
108import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
119import org.jetbrains.kotlin.config.CompilerConfiguration
1210
11+ @OptIn(ExperimentalCompilerApi ::class )
12+ @Suppress(" DEPRECATION" , " DEPRECATION_ERROR" )
1313abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar (), ComponentRegistrar {
1414 override val supportsK2: Boolean
1515 get() = true
@@ -22,11 +22,11 @@ abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar(), ComponentR
2222 project : MockProject ,
2323 configuration : CompilerConfiguration
2424 ) {
25- // In 2.4.0, we use CompilerPluginRegistrar path instead.
26- // This is only called if the compiler uses the ComponentRegistrar service file.
27- // We do nothing here since registerExtensions will be called separately.
25+ this .project = project
26+ doRegisterExtensions(configuration)
2827 }
2928
29+ private var project: MockProject ? = null
3030 private var extensionStorage: CompilerPluginRegistrar .ExtensionStorage ? = null
3131
3232 override fun ExtensionStorage.registerExtensions (configuration : CompilerConfiguration ) {
@@ -37,9 +37,15 @@ abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar(), ComponentR
3737 abstract fun doRegisterExtensions (configuration : CompilerConfiguration )
3838
3939 protected fun registerExtractorExtension (extension : IrGenerationExtension ) {
40- val storage = extensionStorage ? : throw IllegalStateException (" registerExtractorExtension called before registerExtensions" )
41- with (storage) {
42- IrGenerationExtension .registerExtension(extension)
40+ extensionStorage?.let { storage ->
41+ with (storage) {
42+ IrGenerationExtension .registerExtension(extension)
43+ }
44+ return
4345 }
46+ // Fallback for ComponentRegistrar-based registration to keep legacy ordering semantics.
47+ val p = project ? : throw IllegalStateException (" registerExtractorExtension called before registration" )
48+ val extensionPoint = p.extensionArea.getExtensionPoint(IrGenerationExtension .extensionPointName)
49+ extensionPoint.registerExtension(extension, LoadingOrder .LAST , p)
4450 }
4551}
0 commit comments