Remove unused PrecomputedSuppressCache
This commit is contained in:
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.resolve.*
|
|||||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.OnDemandSuppressCache
|
import org.jetbrains.kotlin.resolve.diagnostics.OnDemandSuppressCache
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.PrecomputedSuppressCache
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*
|
||||||
|
|||||||
-47
@@ -14,54 +14,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
|||||||
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
|
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
|
||||||
/**
|
|
||||||
* A [KotlinSuppressCache] implementation that computes all suppressions at the moment of instantiation.
|
|
||||||
* This is useful in the IR backend, where we clear the main binding context after psi2ir to avoid taking extra memory.
|
|
||||||
* To make suppression of errors reported from backend possible though, we need to precompute all resolved `@Suppress` annotations,
|
|
||||||
* and store this information outside of the binding context, which is going to be cleared.
|
|
||||||
*
|
|
||||||
* @param context the binding context where the data should be loaded from. Note that it shouldn't be stored as a property because the
|
|
||||||
* primary use case of this class is when that binding context is cleared and thus is useless after a certain point.
|
|
||||||
*/
|
|
||||||
class PrecomputedSuppressCache(context: BindingContext, files: List<KtFile>) : KotlinSuppressCache() {
|
|
||||||
val storage: Map<PsiElement, List<AnnotationDescriptor>> =
|
|
||||||
mutableMapOf<PsiElement, List<AnnotationDescriptor>>().also { storage ->
|
|
||||||
val visitor = PrecomputingVisitor(storage, BindingContextSuppressCache(context))
|
|
||||||
for (file in files) {
|
|
||||||
file.accept(visitor, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PrecomputingVisitor(
|
|
||||||
val storage: MutableMap<PsiElement, List<AnnotationDescriptor>>,
|
|
||||||
val computer: KotlinSuppressCache,
|
|
||||||
) : KtTreeVisitorVoid() {
|
|
||||||
override fun visitKtElement(element: KtElement) {
|
|
||||||
super.visitKtElement(element)
|
|
||||||
if (element is KtAnnotated) {
|
|
||||||
computeAnnotations(element)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitKtFile(file: KtFile) {
|
|
||||||
super.visitKtFile(file)
|
|
||||||
computeAnnotations(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun computeAnnotations(element: KtAnnotated) {
|
|
||||||
val suppressions = computer.getSuppressionAnnotations(element).filter { it.fqName == StandardNames.FqNames.suppress }
|
|
||||||
if (suppressions.isNotEmpty()) {
|
|
||||||
storage[element] = suppressions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSuppressionAnnotations(annotated: PsiElement): List<AnnotationDescriptor> =
|
|
||||||
storage[annotated].orEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
class OnDemandSuppressCache(private val context: BindingContext) : KotlinSuppressCache() {
|
class OnDemandSuppressCache(private val context: BindingContext) : KotlinSuppressCache() {
|
||||||
|
|
||||||
private val processedRoots = mutableSetOf<KtFile>()
|
private val processedRoots = mutableSetOf<KtFile>()
|
||||||
|
|
||||||
private val storage = mutableMapOf<PsiElement, List<AnnotationDescriptor>>()
|
private val storage = mutableMapOf<PsiElement, List<AnnotationDescriptor>>()
|
||||||
Reference in New Issue
Block a user