[SLC] AnnotationsBox: add an owner to signatures
we shouldn't require the owner on initialization phase ^KT-56046
This commit is contained in:
committed by
Space Team
parent
eaf6798684
commit
ad4f6b25ca
+5
-4
@@ -6,9 +6,10 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiAnnotationOwner
|
||||
import com.intellij.psi.PsiModifierList
|
||||
|
||||
internal sealed interface AnnotationsBox : PsiAnnotationOwner {
|
||||
override fun getApplicableAnnotations(): Array<PsiAnnotation> = annotations
|
||||
override fun addAnnotation(qualifiedName: String): PsiAnnotation = throw UnsupportedOperationException()
|
||||
internal sealed interface AnnotationsBox {
|
||||
fun annotations(owner: PsiModifierList): Array<PsiAnnotation>
|
||||
fun findAnnotation(owner: PsiModifierList, qualifiedName: String): PsiAnnotation?
|
||||
fun hasAnnotation(owner: PsiModifierList, qualifiedName: String): Boolean = findAnnotation(owner, qualifiedName) != null
|
||||
}
|
||||
|
||||
+2
-1
@@ -268,9 +268,10 @@ private fun LazyAnnotationsBox.tryConvertToJavaAnnotation(
|
||||
argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue> = { emptyList() },
|
||||
): PsiAnnotation? {
|
||||
if (qualifiedName != javaQualifier) return null
|
||||
if (hasAnnotation(javaQualifier)) return null
|
||||
if (hasAnnotation(owner, javaQualifier)) return null
|
||||
|
||||
val originalLightAnnotation = findAnnotation(
|
||||
owner,
|
||||
kotlinQualifier,
|
||||
withAdditionalAnnotations = false,
|
||||
) as? SymbolLightLazyAnnotation ?: return null
|
||||
|
||||
+9
-7
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.utils.SmartList
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
internal class LazyAnnotationsBox(
|
||||
private val owner: PsiModifierList,
|
||||
private val annotationsProvider: AnnotationsProvider,
|
||||
private val additionalAnnotationsProvider: AdditionalAnnotationsProvider = DefaultAnnotationsProvider,
|
||||
) : AnnotationsBox {
|
||||
@@ -21,7 +20,7 @@ internal class LazyAnnotationsBox(
|
||||
private var specialAnnotations: SmartList<PsiAnnotation>? = null
|
||||
private val monitor = Any()
|
||||
|
||||
override fun getAnnotations(): Array<PsiAnnotation> {
|
||||
override fun annotations(owner: PsiModifierList): Array<PsiAnnotation> {
|
||||
annotationsArray.get()?.let { return it }
|
||||
|
||||
val classIds = annotationsProvider.classIds()
|
||||
@@ -60,9 +59,12 @@ internal class LazyAnnotationsBox(
|
||||
annotationsArray.get() ?: error("Unexpected state")
|
||||
}
|
||||
|
||||
override fun findAnnotation(qualifiedName: String): PsiAnnotation? = findAnnotation(qualifiedName, withAdditionalAnnotations = true)
|
||||
override fun findAnnotation(
|
||||
owner: PsiModifierList,
|
||||
qualifiedName: String,
|
||||
): PsiAnnotation? = findAnnotation(owner, qualifiedName, withAdditionalAnnotations = true)
|
||||
|
||||
fun findAnnotation(qualifiedName: String, withAdditionalAnnotations: Boolean): PsiAnnotation? {
|
||||
fun findAnnotation(owner: PsiModifierList, qualifiedName: String, withAdditionalAnnotations: Boolean): PsiAnnotation? {
|
||||
annotationsArray.get()?.let { array ->
|
||||
return array.find { it.qualifiedName == qualifiedName }
|
||||
}
|
||||
@@ -84,7 +86,7 @@ internal class LazyAnnotationsBox(
|
||||
}
|
||||
|
||||
if (specialAnnotation == null) {
|
||||
return annotations.find { it.qualifiedName == qualifiedName }
|
||||
return annotations(owner).find { it.qualifiedName == qualifiedName }
|
||||
}
|
||||
|
||||
return synchronized(monitor) {
|
||||
@@ -108,7 +110,7 @@ internal class LazyAnnotationsBox(
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasAnnotation(qualifiedName: String): Boolean {
|
||||
override fun hasAnnotation(owner: PsiModifierList, qualifiedName: String): Boolean {
|
||||
annotationsArray.get()?.let { array ->
|
||||
return array.any { it.qualifiedName == qualifiedName }
|
||||
}
|
||||
@@ -117,7 +119,7 @@ internal class LazyAnnotationsBox(
|
||||
return if (specialAnnotationClassId != null) {
|
||||
specialAnnotationClassId in annotationsProvider
|
||||
} else {
|
||||
annotations.any { it.qualifiedName == qualifiedName }
|
||||
annotations(owner).any { it.qualifiedName == qualifiedName }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-7
@@ -6,14 +6,28 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import com.intellij.psi.PsiModifierList
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
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()
|
||||
internal class SimpleAnnotationsBox(private val annotationsComputer: (PsiModifierList) -> Collection<PsiAnnotation>) : AnnotationsBox {
|
||||
private val annotations: AtomicReference<Array<PsiAnnotation>?> = AtomicReference()
|
||||
|
||||
private fun getOrComputeAnnotations(owner: PsiModifierList): Array<PsiAnnotation> {
|
||||
annotations.get()?.let { return it }
|
||||
|
||||
val nonCachedAnnotations = annotationsComputer(owner)
|
||||
val resultArray = if (nonCachedAnnotations.isEmpty()) PsiAnnotation.EMPTY_ARRAY else nonCachedAnnotations.toTypedArray()
|
||||
return if (annotations.compareAndSet(null, resultArray)) {
|
||||
resultArray
|
||||
} else {
|
||||
getOrComputeAnnotations(owner)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAnnotations(): Array<PsiAnnotation> = lazyAnnotation
|
||||
override fun findAnnotation(qualifiedName: String): PsiAnnotation? = lazyAnnotation.find { it.qualifiedName == qualifiedName }
|
||||
override fun annotations(owner: PsiModifierList): Array<PsiAnnotation> = getOrComputeAnnotations(owner)
|
||||
|
||||
override fun findAnnotation(
|
||||
owner: PsiModifierList,
|
||||
qualifiedName: String,
|
||||
): PsiAnnotation? = getOrComputeAnnotations(owner).find { it.qualifiedName == qualifiedName }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user