[kotlin] Provide a link to the K2 migration guide on accessing K1 services from K2 mode

#KTIJ-31463 Fixed

GitOrigin-RevId: 785c71821bd597b9ec2cdf862b2d6e4176df43ef
This commit is contained in:
Vladimir Dolzhenko
2024-10-01 18:15:36 +02:00
committed by intellij-monorepo-bot
parent 90708008c0
commit 2977a5106d
3 changed files with 26 additions and 2 deletions

View File

@@ -32,5 +32,6 @@
<orderEntry type="module" module-name="intellij.java" />
<orderEntry type="module" module-name="intellij.java.analysis" />
<orderEntry type="module" module-name="kotlin.base.statistics" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
</component>
</module>

View File

@@ -2,7 +2,6 @@
package org.jetbrains.kotlin.caches.resolve
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.analyzer.ModuleInfo
@@ -11,10 +10,11 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache
import org.jetbrains.kotlin.util.k1Service
interface KotlinCacheService {
companion object {
fun getInstance(project: Project): KotlinCacheService = project.service()
fun getInstance(project: Project): KotlinCacheService = project.k1Service()
}
/**

View File

@@ -0,0 +1,23 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.util
import com.intellij.openapi.components.ComponentManager
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
inline fun <reified T : Any> ComponentManager.k1Service(): T {
val serviceClass = T::class.java
getService(serviceClass)?.let { return it }
val name = serviceClass.name
throw if (KotlinPluginModeProvider.isK2Mode()) {
IllegalStateException("$name should not be used for the K2 mode. See https://kotl.in/analysis-api/ for the migration.")
} else {
IllegalStateException(
"Cannot find service $name (" +
"classloader=${serviceClass.classLoader}, " +
"serviceContainer=$this, " +
"serviceContainerClass=${this::class.java.name}" +
")"
)
}
}