Don't keep ref to ABSENT_KOTLIN_INJECTION in companion object

As it prevents from dynamic reloading of plugin

^KT-39958 Fixed
This commit is contained in:
Vladimir Dolzhenko
2020-10-09 21:48:01 +02:00
committed by Vladimir Dolzhenko
parent 7c2112d014
commit 677f5ca4e3
@@ -56,11 +56,11 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KotlinLanguageInjector(
private val project: Project
) : MultiHostInjector {
private val absentKotlinInjection = BaseInjection("ABSENT_KOTLIN_BASE_INJECTION")
private val configuration get() = Configuration.getProjectInstance(project)
companion object {
private val STRING_LITERALS_REGEXP = "\"([^\"]*)\"".toRegex()
private val ABSENT_KOTLIN_INJECTION = BaseInjection("ABSENT_KOTLIN_BASE_INJECTION")
}
private val kotlinSupport: KotlinLanguageInjectionSupport? by lazy {
@@ -88,14 +88,14 @@ class KotlinLanguageInjector(
val baseInjection = when {
needImmediateAnswer -> {
// Can't afford long counting or typing will be laggy. Force cache reuse even if it's outdated.
kotlinCachedInjection?.baseInjection ?: ABSENT_KOTLIN_INJECTION
kotlinCachedInjection?.baseInjection ?: absentKotlinInjection
}
kotlinCachedInjection != null && (modificationCount == kotlinCachedInjection.modificationCount) ->
// Cache is up-to-date
kotlinCachedInjection.baseInjection
else -> {
fun computeAndCache(): BaseInjection {
val computedInjection = computeBaseInjection(ktHost, support) ?: ABSENT_KOTLIN_INJECTION
val computedInjection = computeBaseInjection(ktHost, support) ?: absentKotlinInjection
ktHost.cachedInjectionWithModification = KotlinCachedInjection(modificationCount, computedInjection)
return computedInjection
}
@@ -104,14 +104,14 @@ class KotlinLanguageInjector(
// The action cannot be canceled by caller and by internal checkCanceled() calls.
// Force creating new indicator that is canceled on write action start, otherwise there might be lags in typing.
runInReadActionWithWriteActionPriority(::computeAndCache) ?: kotlinCachedInjection?.baseInjection
?: ABSENT_KOTLIN_INJECTION
?: absentKotlinInjection
} else {
computeAndCache()
}
}
}
if (baseInjection == ABSENT_KOTLIN_INJECTION) {
if (baseInjection == absentKotlinInjection) {
return
}