[LC] reduce memory consumption from SLC and DLC

The main change is drop `LightClassesLazyCreator`

KtLightClassForDecompiledDeclaration:
* fixed a few captured fields

^KT-56561 Fixed
This commit is contained in:
Dmitrii Gridin
2023-02-10 16:07:29 +01:00
committed by Space Team
parent a8e8fc1f11
commit 761553ea75
6 changed files with 336 additions and 184 deletions
@@ -7,15 +7,16 @@ package org.jetbrains.kotlin.light.classes.symbol.classes
import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProviders
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Pair
import com.intellij.openapi.util.TextRange
import com.intellij.psi.*
import com.intellij.psi.impl.*
import com.intellij.psi.impl.InheritanceImplUtil
import com.intellij.psi.impl.PsiClassImplUtil
import com.intellij.psi.impl.PsiImplUtil
import com.intellij.psi.impl.PsiSuperMethodImplUtil
import com.intellij.psi.impl.light.LightElement
import com.intellij.psi.javadoc.PsiDocComment
import com.intellij.psi.scope.PsiScopeProcessor
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.PsiUtil
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.analysis.project.structure.KtModule
@@ -33,30 +34,15 @@ import javax.swing.Icon
abstract class SymbolLightClassBase protected constructor(val ktModule: KtModule, manager: PsiManager) :
LightElement(manager, KotlinLanguage.INSTANCE), PsiClass, KtExtensibleLightClass {
private class SymbolLightClassesLazyCreator(private val project: Project) : KotlinClassInnerStuffCache.LazyCreator() {
override fun <T : Any> get(initializer: () -> T, dependencies: List<Any>): Lazy<T> = object : Lazy<T> {
private val cachedValue = PsiCachedValueImpl(PsiManager.getInstance(project)) {
CachedValueProvider.Result.create(initializer(), dependencies)
}
override val value: T get() = cachedValue.value ?: error("Unexpected null value from PsiCachedValueImpl")
override fun isInitialized(): Boolean {
// Lazy is a bad interface here as it has unneeded and unused in LC `isInitialized` method
// considering Interface Segregation Principle, Lazy should be repaced with a simpler interface with only `value` method
error("Should not be called for LC")
}
}
private val myInnersCache by lazyPub {
ClassInnerStuffCache(
/* aClass = */ this,
/* generateEnumMethods = */ false,
/* modificationTracker = */ project.createProjectWideOutOfBlockModificationTracker(),
)
}
@Suppress("LeakingThis")
private val myInnersCache = KotlinClassInnerStuffCache(
myClass = this@SymbolLightClassBase,
dependencies = listOf(manager.project.createProjectWideOutOfBlockModificationTracker()),
lazyCreator = SymbolLightClassesLazyCreator(project),
generateEnumMethods = false,
)
override fun getFields(): Array<PsiField> = myInnersCache.fields
override fun getMethods(): Array<PsiMethod> = myInnersCache.methods