[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
|
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
|
||||||
|
|
||||||
internal sealed interface AnnotationsBox : PsiAnnotationOwner {
|
internal sealed interface AnnotationsBox {
|
||||||
override fun getApplicableAnnotations(): Array<PsiAnnotation> = annotations
|
fun annotations(owner: PsiModifierList): Array<PsiAnnotation>
|
||||||
override fun addAnnotation(qualifiedName: String): PsiAnnotation = throw UnsupportedOperationException()
|
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() },
|
argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue> = { emptyList() },
|
||||||
): PsiAnnotation? {
|
): PsiAnnotation? {
|
||||||
if (qualifiedName != javaQualifier) return null
|
if (qualifiedName != javaQualifier) return null
|
||||||
if (hasAnnotation(javaQualifier)) return null
|
if (hasAnnotation(owner, javaQualifier)) return null
|
||||||
|
|
||||||
val originalLightAnnotation = findAnnotation(
|
val originalLightAnnotation = findAnnotation(
|
||||||
|
owner,
|
||||||
kotlinQualifier,
|
kotlinQualifier,
|
||||||
withAdditionalAnnotations = false,
|
withAdditionalAnnotations = false,
|
||||||
) as? SymbolLightLazyAnnotation ?: return null
|
) as? SymbolLightLazyAnnotation ?: return null
|
||||||
|
|||||||
+9
-7
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.utils.SmartList
|
|||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
internal class LazyAnnotationsBox(
|
internal class LazyAnnotationsBox(
|
||||||
private val owner: PsiModifierList,
|
|
||||||
private val annotationsProvider: AnnotationsProvider,
|
private val annotationsProvider: AnnotationsProvider,
|
||||||
private val additionalAnnotationsProvider: AdditionalAnnotationsProvider = DefaultAnnotationsProvider,
|
private val additionalAnnotationsProvider: AdditionalAnnotationsProvider = DefaultAnnotationsProvider,
|
||||||
) : AnnotationsBox {
|
) : AnnotationsBox {
|
||||||
@@ -21,7 +20,7 @@ internal class LazyAnnotationsBox(
|
|||||||
private var specialAnnotations: SmartList<PsiAnnotation>? = null
|
private var specialAnnotations: SmartList<PsiAnnotation>? = null
|
||||||
private val monitor = Any()
|
private val monitor = Any()
|
||||||
|
|
||||||
override fun getAnnotations(): Array<PsiAnnotation> {
|
override fun annotations(owner: PsiModifierList): Array<PsiAnnotation> {
|
||||||
annotationsArray.get()?.let { return it }
|
annotationsArray.get()?.let { return it }
|
||||||
|
|
||||||
val classIds = annotationsProvider.classIds()
|
val classIds = annotationsProvider.classIds()
|
||||||
@@ -60,9 +59,12 @@ internal class LazyAnnotationsBox(
|
|||||||
annotationsArray.get() ?: error("Unexpected state")
|
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 ->
|
annotationsArray.get()?.let { array ->
|
||||||
return array.find { it.qualifiedName == qualifiedName }
|
return array.find { it.qualifiedName == qualifiedName }
|
||||||
}
|
}
|
||||||
@@ -84,7 +86,7 @@ internal class LazyAnnotationsBox(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (specialAnnotation == null) {
|
if (specialAnnotation == null) {
|
||||||
return annotations.find { it.qualifiedName == qualifiedName }
|
return annotations(owner).find { it.qualifiedName == qualifiedName }
|
||||||
}
|
}
|
||||||
|
|
||||||
return synchronized(monitor) {
|
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 ->
|
annotationsArray.get()?.let { array ->
|
||||||
return array.any { it.qualifiedName == qualifiedName }
|
return array.any { it.qualifiedName == qualifiedName }
|
||||||
}
|
}
|
||||||
@@ -117,7 +119,7 @@ internal class LazyAnnotationsBox(
|
|||||||
return if (specialAnnotationClassId != null) {
|
return if (specialAnnotationClassId != null) {
|
||||||
specialAnnotationClassId in annotationsProvider
|
specialAnnotationClassId in annotationsProvider
|
||||||
} else {
|
} 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
|
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||||
|
|
||||||
import com.intellij.psi.PsiAnnotation
|
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 {
|
internal class SimpleAnnotationsBox(private val annotationsComputer: (PsiModifierList) -> Collection<PsiAnnotation>) : AnnotationsBox {
|
||||||
private val lazyAnnotation: Array<PsiAnnotation> by lazyPub {
|
private val annotations: AtomicReference<Array<PsiAnnotation>?> = AtomicReference()
|
||||||
val annotations = annotationsComputer()
|
|
||||||
if (annotations.isEmpty()) PsiAnnotation.EMPTY_ARRAY else annotations.toTypedArray()
|
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 annotations(owner: PsiModifierList): Array<PsiAnnotation> = getOrComputeAnnotations(owner)
|
||||||
override fun findAnnotation(qualifiedName: String): PsiAnnotation? = lazyAnnotation.find { it.qualifiedName == qualifiedName }
|
|
||||||
|
override fun findAnnotation(
|
||||||
|
owner: PsiModifierList,
|
||||||
|
qualifiedName: String,
|
||||||
|
): PsiAnnotation? = getOrComputeAnnotations(owner).find { it.qualifiedName == qualifiedName }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user