[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.impl.PsiSuperMethodImplUtil
|
||||||
import com.intellij.psi.javadoc.PsiDocComment
|
import com.intellij.psi.javadoc.PsiDocComment
|
||||||
import com.intellij.psi.scope.PsiScopeProcessor
|
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 com.intellij.psi.util.PsiUtil
|
||||||
import org.jetbrains.annotations.NonNls
|
import org.jetbrains.annotations.NonNls
|
||||||
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
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.load.java.structure.LightClassOriginKind
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
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(
|
open class KtLightClassForDecompiledDeclaration(
|
||||||
clsDelegate: PsiClass,
|
clsDelegate: PsiClass,
|
||||||
clsParent: PsiElement,
|
clsParent: PsiElement,
|
||||||
@@ -118,8 +126,7 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
override fun getAllMethods(): Array<PsiMethod> = PsiClassImplUtil.getAllMethods(this)
|
override fun getAllMethods(): Array<PsiMethod> = PsiClassImplUtil.getAllMethods(this)
|
||||||
override fun getAllFields(): Array<PsiField> = PsiClassImplUtil.getAllFields(this)
|
override fun getAllFields(): Array<PsiField> = PsiClassImplUtil.getAllFields(this)
|
||||||
|
|
||||||
override fun getOwnMethods(): List<PsiMethod> = _ownMethods
|
override fun getOwnMethods(): List<PsiMethod> = cachedValueWithLibraryTracker {
|
||||||
private val _ownMethods: List<PsiMethod> by lazyPub {
|
|
||||||
val isEnum = isEnum
|
val isEnum = isEnum
|
||||||
this.clsDelegate.methods.mapNotNull { psiMethod ->
|
this.clsDelegate.methods.mapNotNull { psiMethod ->
|
||||||
if (isSyntheticValuesOrValueOfMethod(psiMethod)) return@mapNotNull null
|
if (isSyntheticValuesOrValueOfMethod(psiMethod)) return@mapNotNull null
|
||||||
@@ -135,8 +142,7 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwnFields(): List<PsiField> = _ownFields
|
override fun getOwnFields(): List<PsiField> = cachedValueWithLibraryTracker {
|
||||||
private val _ownFields: List<PsiField> by lazyPub {
|
|
||||||
this.clsDelegate.fields.map { psiField ->
|
this.clsDelegate.fields.map { psiField ->
|
||||||
if (psiField is PsiEnumConstant) {
|
if (psiField is PsiEnumConstant) {
|
||||||
KtLightEnumEntryForDecompiledDeclaration(
|
KtLightEnumEntryForDecompiledDeclaration(
|
||||||
@@ -155,8 +161,7 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwnInnerClasses(): List<PsiClass> = _ownInnerClasses
|
override fun getOwnInnerClasses(): List<PsiClass> = cachedValueWithLibraryTracker {
|
||||||
private val _ownInnerClasses: List<PsiClass> by lazyPub {
|
|
||||||
this.clsDelegate.innerClasses.map { psiClass ->
|
this.clsDelegate.innerClasses.map { psiClass ->
|
||||||
val innerDeclaration = this.kotlinOrigin
|
val innerDeclaration = this.kotlinOrigin
|
||||||
?.declarations
|
?.declarations
|
||||||
|
|||||||
+1
-3
@@ -5,7 +5,6 @@ package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
|||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
||||||
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
|
||||||
|
|
||||||
internal class KtLightEnumEntryForDecompiledDeclaration(
|
internal class KtLightEnumEntryForDecompiledDeclaration(
|
||||||
private val fldDelegate: PsiEnumConstant,
|
private val fldDelegate: PsiEnumConstant,
|
||||||
@@ -22,8 +21,7 @@ internal class KtLightEnumEntryForDecompiledDeclaration(
|
|||||||
override fun resolveMethod(): PsiMethod? = fldDelegate.resolveMethod()
|
override fun resolveMethod(): PsiMethod? = fldDelegate.resolveMethod()
|
||||||
override fun resolveMethodGenerics(): JavaResolveResult = fldDelegate.resolveMethodGenerics()
|
override fun resolveMethodGenerics(): JavaResolveResult = fldDelegate.resolveMethodGenerics()
|
||||||
|
|
||||||
override fun getInitializingClass(): PsiEnumConstantInitializer? = _initializingClass
|
override fun getInitializingClass(): PsiEnumConstantInitializer? = cachedValueWithLibraryTracker {
|
||||||
private val _initializingClass: PsiEnumConstantInitializer? by lazyPub {
|
|
||||||
fldDelegate.initializingClass?.let {
|
fldDelegate.initializingClass?.let {
|
||||||
KtLightEnumClassForDecompiledDeclaration(
|
KtLightEnumClassForDecompiledDeclaration(
|
||||||
psiConstantInitializer = it,
|
psiConstantInitializer = it,
|
||||||
|
|||||||
+2
-1
@@ -55,7 +55,8 @@ open class KtLightFieldForDecompiledDeclaration(
|
|||||||
|
|
||||||
override fun computeConstantValue(): Any? = fldDelegate.computeConstantValue()
|
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 ||
|
override fun equals(other: Any?): Boolean = other === this ||
|
||||||
other is KtLightFieldForDecompiledDeclaration &&
|
other is KtLightFieldForDecompiledDeclaration &&
|
||||||
|
|||||||
Reference in New Issue
Block a user