[DLC] drop hard references to member declarations to reduce memory consumption
^KT-56613
This commit is contained in:
committed by
Space Team
parent
e20f72fcf8
commit
7af78db2e1
+11
-6
@@ -12,6 +12,8 @@ import com.intellij.psi.impl.PsiImplUtil
|
||||
import com.intellij.psi.impl.PsiSuperMethodImplUtil
|
||||
import com.intellij.psi.javadoc.PsiDocComment
|
||||
import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiUtil
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
||||
@@ -26,6 +28,12 @@ import org.jetbrains.kotlin.asJava.isSyntheticValuesOrValueOfMethod
|
||||
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
|
||||
internal inline fun <R : PsiElement, T> R.cachedValueWithLibraryTracker(
|
||||
crossinline computer: () -> T,
|
||||
): T = CachedValuesManager.getCachedValue(this) {
|
||||
CachedValueProvider.Result.createSingleDependency(computer(), project.createAllLibrariesModificationTracker())
|
||||
}
|
||||
|
||||
open class KtLightClassForDecompiledDeclaration(
|
||||
clsDelegate: PsiClass,
|
||||
clsParent: PsiElement,
|
||||
@@ -118,8 +126,7 @@ open class KtLightClassForDecompiledDeclaration(
|
||||
override fun getAllMethods(): Array<PsiMethod> = PsiClassImplUtil.getAllMethods(this)
|
||||
override fun getAllFields(): Array<PsiField> = PsiClassImplUtil.getAllFields(this)
|
||||
|
||||
override fun getOwnMethods(): List<PsiMethod> = _ownMethods
|
||||
private val _ownMethods: List<PsiMethod> by lazyPub {
|
||||
override fun getOwnMethods(): List<PsiMethod> = cachedValueWithLibraryTracker {
|
||||
val isEnum = isEnum
|
||||
this.clsDelegate.methods.mapNotNull { psiMethod ->
|
||||
if (isSyntheticValuesOrValueOfMethod(psiMethod)) return@mapNotNull null
|
||||
@@ -135,8 +142,7 @@ open class KtLightClassForDecompiledDeclaration(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getOwnFields(): List<PsiField> = _ownFields
|
||||
private val _ownFields: List<PsiField> by lazyPub {
|
||||
override fun getOwnFields(): List<PsiField> = cachedValueWithLibraryTracker {
|
||||
this.clsDelegate.fields.map { psiField ->
|
||||
if (psiField is PsiEnumConstant) {
|
||||
KtLightEnumEntryForDecompiledDeclaration(
|
||||
@@ -155,8 +161,7 @@ open class KtLightClassForDecompiledDeclaration(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getOwnInnerClasses(): List<PsiClass> = _ownInnerClasses
|
||||
private val _ownInnerClasses: List<PsiClass> by lazyPub {
|
||||
override fun getOwnInnerClasses(): List<PsiClass> = cachedValueWithLibraryTracker {
|
||||
this.clsDelegate.innerClasses.map { psiClass ->
|
||||
val innerDeclaration = this.kotlinOrigin
|
||||
?.declarations
|
||||
|
||||
+1
-3
@@ -5,7 +5,6 @@ package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
||||
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
|
||||
internal class KtLightEnumEntryForDecompiledDeclaration(
|
||||
private val fldDelegate: PsiEnumConstant,
|
||||
@@ -22,8 +21,7 @@ internal class KtLightEnumEntryForDecompiledDeclaration(
|
||||
override fun resolveMethod(): PsiMethod? = fldDelegate.resolveMethod()
|
||||
override fun resolveMethodGenerics(): JavaResolveResult = fldDelegate.resolveMethodGenerics()
|
||||
|
||||
override fun getInitializingClass(): PsiEnumConstantInitializer? = _initializingClass
|
||||
private val _initializingClass: PsiEnumConstantInitializer? by lazyPub {
|
||||
override fun getInitializingClass(): PsiEnumConstantInitializer? = cachedValueWithLibraryTracker {
|
||||
fldDelegate.initializingClass?.let {
|
||||
KtLightEnumClassForDecompiledDeclaration(
|
||||
psiConstantInitializer = it,
|
||||
|
||||
+2
-1
@@ -55,7 +55,8 @@ open class KtLightFieldForDecompiledDeclaration(
|
||||
|
||||
override fun computeConstantValue(): Any? = fldDelegate.computeConstantValue()
|
||||
|
||||
override fun computeConstantValue(visitedVars: MutableSet<PsiVariable>?): Any? = (fldDelegate as? PsiVariableEx)?.computeConstantValue(visitedVars)
|
||||
override fun computeConstantValue(visitedVars: MutableSet<PsiVariable>?): Any? =
|
||||
(fldDelegate as? PsiVariableEx)?.computeConstantValue(visitedVars)
|
||||
|
||||
override fun equals(other: Any?): Boolean = other === this ||
|
||||
other is KtLightFieldForDecompiledDeclaration &&
|
||||
|
||||
Reference in New Issue
Block a user