[SLC] introduce SimpleAnnotationsBox

^KT-56046
This commit is contained in:
Dmitrii Gridin
2023-01-24 19:58:16 +01:00
committed by Space Team
parent 465ac23650
commit c401cd3210
3 changed files with 34 additions and 6 deletions
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiAnnotationOwner
internal sealed interface AnnotationsBox : PsiAnnotationOwner {
override fun getApplicableAnnotations(): Array<PsiAnnotation> = annotations
override fun addAnnotation(qualifiedName: String): PsiAnnotation = throw UnsupportedOperationException()
}
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiAnnotationOwner
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.name.StandardClassIds
@@ -17,7 +16,7 @@ internal class LazyAnnotationsBox(
private val owner: PsiModifierList, private val owner: PsiModifierList,
private val annotationsProvider: AnnotationsProvider, private val annotationsProvider: AnnotationsProvider,
private val additionalAnnotationsProvider: AdditionalAnnotationsProvider = DefaultAnnotationsProvider, private val additionalAnnotationsProvider: AdditionalAnnotationsProvider = DefaultAnnotationsProvider,
) : PsiAnnotationOwner { ) : AnnotationsBox {
private val annotationsArray: AtomicReference<Array<PsiAnnotation>?> = AtomicReference() private val annotationsArray: AtomicReference<Array<PsiAnnotation>?> = AtomicReference()
private var specialAnnotations: SmartList<PsiAnnotation>? = null private var specialAnnotations: SmartList<PsiAnnotation>? = null
private val monitor = Any() private val monitor = Any()
@@ -61,8 +60,6 @@ internal class LazyAnnotationsBox(
annotationsArray.get() ?: error("Unexpected state") annotationsArray.get() ?: error("Unexpected state")
} }
override fun getApplicableAnnotations(): Array<PsiAnnotation> = annotations
override fun findAnnotation(qualifiedName: String): PsiAnnotation? = findAnnotation(qualifiedName, withAdditionalAnnotations = true) override fun findAnnotation(qualifiedName: String): PsiAnnotation? = findAnnotation(qualifiedName, withAdditionalAnnotations = true)
fun findAnnotation(qualifiedName: String, withAdditionalAnnotations: Boolean): PsiAnnotation? { fun findAnnotation(qualifiedName: String, withAdditionalAnnotations: Boolean): PsiAnnotation? {
@@ -124,8 +121,6 @@ internal class LazyAnnotationsBox(
} }
} }
override fun addAnnotation(qualifiedName: String): PsiAnnotation = throw UnsupportedOperationException()
companion object { companion object {
/** /**
* @see org.jetbrains.kotlin.fir.resolve.transformers.plugin.CompilerRequiredAnnotationsHelper * @see org.jetbrains.kotlin.fir.resolve.transformers.plugin.CompilerRequiredAnnotationsHelper
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation
import org.jetbrains.kotlin.asJava.classes.lazyPub
internal class SimpleAnnotationsBox(annotationsComputer: () -> Collection<PsiAnnotation>) : AnnotationsBox {
private val lazyAnnotation: Array<PsiAnnotation> by lazyPub {
val annotations = annotationsComputer()
if (annotations.isEmpty()) PsiAnnotation.EMPTY_ARRAY else annotations.toTypedArray()
}
override fun getAnnotations(): Array<PsiAnnotation> = lazyAnnotation
override fun findAnnotation(qualifiedName: String): PsiAnnotation? = lazyAnnotation.find { it.qualifiedName == qualifiedName }
}