Remove reference to binding context from LazyLightClassDataHolder cache

The ultimate goal is to remove references to binding context and resolve
result from light classes. There still can be references from `diagnostics`
field, but `bindingContext` is unneeded and can be removed.

Relates to snapshots from IDEA-187395.
This commit is contained in:
Nikolay Krasko
2018-03-16 11:38:42 +03:00
parent 481a5bc28d
commit 14a0434737
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
import org.jetbrains.kotlin.psi.debugText.getDebugText import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
typealias ExactLightClassContextProvider = () -> LightClassConstructionContext typealias ExactLightClassContextProvider = () -> LightClassConstructionContext
@@ -38,16 +39,23 @@ sealed class LazyLightClassDataHolder(
isLocal: Boolean = false isLocal: Boolean = false
) : LightClassDataHolder { ) : LightClassDataHolder {
private data class CachedLightClassBuilderResult(val stub: PsiJavaFileStub, val diagnostics: Diagnostics)
private val exactResultCachedValue = private val exactResultCachedValue =
CachedValuesManager.getManager(project).createCachedValue({ CachedValuesManager.getManager(project).createCachedValue(
CachedValueProvider.Result.create( {
builder(exactContextProvider()), val (stub, _, diagnostics) = builder(exactContextProvider())
if (isLocal) val cachedResult = CachedLightClassBuilderResult(stub, diagnostics)
PsiModificationTracker.MODIFICATION_COUNT
else CachedValueProvider.Result.create(
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT cachedResult,
) if (isLocal)
}, false) PsiModificationTracker.MODIFICATION_COUNT
else
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
)
}, false
)
private val lazyInexactStub by lazyPub { private val lazyInexactStub by lazyPub {
dummyContextProvider?.let { provider -> provider()?.let { context -> builder.invoke(context).stub } } dummyContextProvider?.let { provider -> provider()?.let { context -> builder.invoke(context).stub } }