[SLC] AnnotationsBox: use PsiElement instead of PsiModifierList

Not only PsiModifierList can be the parent of an annotation,
so we should make the restrictions less aggressive.

^KT-65112
This commit is contained in:
Dmitrii Gridin
2024-02-14 14:59:27 +01:00
committed by Space Team
parent 717dd08fd4
commit ae8e9749c8
14 changed files with 73 additions and 75 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiClass import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.analysis.api.annotations.* import org.jetbrains.kotlin.analysis.api.annotations.*
import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
@@ -24,7 +23,7 @@ internal object AbstractClassAdditionalAnnotationsProvider : AdditionalAnnotatio
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList owner: PsiElement
) { ) {
if (!owner.parent.isAnnotationClass()) return if (!owner.parent.isAnnotationClass()) return
@@ -34,7 +33,7 @@ internal object AbstractClassAdditionalAnnotationsProvider : AdditionalAnnotatio
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = if (owner.parent.isAnnotationClass()) ): PsiAnnotation? = if (owner.parent.isAnnotationClass())
findAdditionalAnnotationFromAnnotationClass(annotationsBox, qualifiedName, owner) findAdditionalAnnotationFromAnnotationClass(annotationsBox, qualifiedName, owner)
else else
@@ -48,7 +47,7 @@ private fun PsiElement.isAnnotationClass(): Boolean = this is PsiClass && isAnno
private fun addAllAnnotationsFromAnnotationClass( private fun addAllAnnotationsFromAnnotationClass(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList, owner: PsiElement,
) { ) {
for (index in currentRawAnnotations.indices) { for (index in currentRawAnnotations.indices) {
val currentAnnotation = currentRawAnnotations[index] as? SymbolLightLazyAnnotation ?: continue val currentAnnotation = currentRawAnnotations[index] as? SymbolLightLazyAnnotation ?: continue
@@ -73,7 +72,7 @@ private fun addAllAnnotationsFromAnnotationClass(
private fun findAdditionalAnnotationFromAnnotationClass( private fun findAdditionalAnnotationFromAnnotationClass(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = annotationsBox.tryConvertToRetentionJavaAnnotation(qualifiedName, owner) ): PsiAnnotation? = annotationsBox.tryConvertToRetentionJavaAnnotation(qualifiedName, owner)
?: annotationsBox.tryConvertToTargetJavaAnnotation(qualifiedName, owner) ?: annotationsBox.tryConvertToTargetJavaAnnotation(qualifiedName, owner)
?: annotationsBox.tryConvertToDocumentedJavaAnnotation(qualifiedName, owner) ?: annotationsBox.tryConvertToDocumentedJavaAnnotation(qualifiedName, owner)
@@ -82,7 +81,7 @@ private fun findAdditionalAnnotationFromAnnotationClass(
private fun GranularAnnotationsBox.tryConvertToDocumentedJavaAnnotation( private fun GranularAnnotationsBox.tryConvertToDocumentedJavaAnnotation(
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
qualifiedName = qualifiedName, qualifiedName = qualifiedName,
javaQualifier = JvmAnnotationNames.DOCUMENTED_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.DOCUMENTED_ANNOTATION.asString(),
@@ -91,7 +90,7 @@ private fun GranularAnnotationsBox.tryConvertToDocumentedJavaAnnotation(
) )
private fun SymbolLightLazyAnnotation.tryConvertToDocumentedJavaAnnotation( private fun SymbolLightLazyAnnotation.tryConvertToDocumentedJavaAnnotation(
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
javaQualifier = JvmAnnotationNames.DOCUMENTED_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.DOCUMENTED_ANNOTATION.asString(),
kotlinQualifier = StandardNames.FqNames.mustBeDocumented.asString(), kotlinQualifier = StandardNames.FqNames.mustBeDocumented.asString(),
@@ -100,7 +99,7 @@ private fun SymbolLightLazyAnnotation.tryConvertToDocumentedJavaAnnotation(
private fun GranularAnnotationsBox.tryConvertToRetentionJavaAnnotation( private fun GranularAnnotationsBox.tryConvertToRetentionJavaAnnotation(
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? { ): PsiAnnotation? {
val javaQualifier = JvmAnnotationNames.RETENTION_ANNOTATION.asString() val javaQualifier = JvmAnnotationNames.RETENTION_ANNOTATION.asString()
return tryConvertToJavaAnnotation( return tryConvertToJavaAnnotation(
@@ -113,7 +112,7 @@ private fun GranularAnnotationsBox.tryConvertToRetentionJavaAnnotation(
} }
private fun SymbolLightLazyAnnotation.tryConvertToRetentionJavaAnnotation( private fun SymbolLightLazyAnnotation.tryConvertToRetentionJavaAnnotation(
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
javaQualifier = JvmAnnotationNames.RETENTION_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.RETENTION_ANNOTATION.asString(),
kotlinQualifier = StandardNames.FqNames.retention.asString(), kotlinQualifier = StandardNames.FqNames.retention.asString(),
@@ -133,7 +132,7 @@ private fun SymbolLightJavaAnnotation.computeJavaRetentionArguments(): List<KtNa
return javaRetentionArguments(kotlinRetentionName) return javaRetentionArguments(kotlinRetentionName)
} }
private fun createRetentionJavaAnnotation(owner: PsiModifierList): PsiAnnotation = SymbolLightSimpleAnnotation( private fun createRetentionJavaAnnotation(owner: PsiElement): PsiAnnotation = SymbolLightSimpleAnnotation(
fqName = JvmAnnotationNames.RETENTION_ANNOTATION.asString(), fqName = JvmAnnotationNames.RETENTION_ANNOTATION.asString(),
parent = owner, parent = owner,
arguments = javaRetentionArguments(kotlinRetentionName = null), arguments = javaRetentionArguments(kotlinRetentionName = null),
@@ -159,7 +158,7 @@ private fun retentionMapping(name: String): String = when (name) {
private fun GranularAnnotationsBox.tryConvertToRepeatableJavaAnnotation( private fun GranularAnnotationsBox.tryConvertToRepeatableJavaAnnotation(
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
qualifiedName = qualifiedName, qualifiedName = qualifiedName,
javaQualifier = JvmAnnotationNames.REPEATABLE_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.REPEATABLE_ANNOTATION.asString(),
@@ -169,7 +168,7 @@ private fun GranularAnnotationsBox.tryConvertToRepeatableJavaAnnotation(
) )
private fun SymbolLightLazyAnnotation.tryConvertToRepeatableJavaAnnotation( private fun SymbolLightLazyAnnotation.tryConvertToRepeatableJavaAnnotation(
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
javaQualifier = JvmAnnotationNames.REPEATABLE_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.REPEATABLE_ANNOTATION.asString(),
kotlinQualifier = StandardNames.FqNames.repeatable.asString(), kotlinQualifier = StandardNames.FqNames.repeatable.asString(),
@@ -193,7 +192,7 @@ private fun SymbolLightJavaAnnotation.computeRepeatableJavaAnnotationArguments()
private fun GranularAnnotationsBox.tryConvertToTargetJavaAnnotation( private fun GranularAnnotationsBox.tryConvertToTargetJavaAnnotation(
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
qualifiedName = qualifiedName, qualifiedName = qualifiedName,
javaQualifier = JvmAnnotationNames.TARGET_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.TARGET_ANNOTATION.asString(),
@@ -203,7 +202,7 @@ private fun GranularAnnotationsBox.tryConvertToTargetJavaAnnotation(
) )
private fun SymbolLightLazyAnnotation.tryConvertToTargetJavaAnnotation( private fun SymbolLightLazyAnnotation.tryConvertToTargetJavaAnnotation(
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = tryConvertToJavaAnnotation( ): PsiAnnotation? = tryConvertToJavaAnnotation(
javaQualifier = JvmAnnotationNames.TARGET_ANNOTATION.asString(), javaQualifier = JvmAnnotationNames.TARGET_ANNOTATION.asString(),
kotlinQualifier = StandardNames.FqNames.target.asString(), kotlinQualifier = StandardNames.FqNames.target.asString(),
@@ -262,7 +261,7 @@ private fun GranularAnnotationsBox.tryConvertToJavaAnnotation(
qualifiedName: String, qualifiedName: String,
javaQualifier: String, javaQualifier: String,
kotlinQualifier: String, kotlinQualifier: String,
owner: PsiModifierList, owner: PsiElement,
argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue> = { emptyList() }, argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue> = { emptyList() },
): PsiAnnotation? { ): PsiAnnotation? {
if (qualifiedName != javaQualifier) return null if (qualifiedName != javaQualifier) return null
@@ -285,7 +284,7 @@ private fun GranularAnnotationsBox.tryConvertToJavaAnnotation(
private fun SymbolLightLazyAnnotation.tryConvertToJavaAnnotation( private fun SymbolLightLazyAnnotation.tryConvertToJavaAnnotation(
javaQualifier: String, javaQualifier: String,
kotlinQualifier: String, kotlinQualifier: String,
owner: PsiModifierList, owner: PsiElement,
argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue> = { emptyList() }, argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue> = { emptyList() },
): PsiAnnotation? { ): PsiAnnotation? {
if (qualifiedName != kotlinQualifier) return null if (qualifiedName != kotlinQualifier) return null
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
/** /**
* This class provides more annotation in addition to [AnnotationsProvider]. * This class provides more annotation in addition to [AnnotationsProvider].
@@ -27,7 +27,7 @@ internal sealed interface AdditionalAnnotationsProvider {
* @param foundQualifiers a list of already presented qualifiers. Used to optimize computation * @param foundQualifiers a list of already presented qualifiers. Used to optimize computation
* @param owner an owner for new annotations * @param owner an owner for new annotations
*/ */
fun addAllAnnotations(currentRawAnnotations: MutableList<in PsiAnnotation>, foundQualifiers: MutableSet<String>, owner: PsiModifierList) fun addAllAnnotations(currentRawAnnotations: MutableList<in PsiAnnotation>, foundQualifiers: MutableSet<String>, owner: PsiElement)
/** /**
* @return **true** if this qualifier should be treated as a **special** in [GranularAnnotationsBox.findAnnotation] * @return **true** if this qualifier should be treated as a **special** in [GranularAnnotationsBox.findAnnotation]
@@ -44,7 +44,7 @@ internal sealed interface AdditionalAnnotationsProvider {
* *
* @return a new annotation with [qualifiedName] * @return a new annotation with [qualifiedName]
*/ */
fun findSpecialAnnotation(annotationsBox: GranularAnnotationsBox, qualifiedName: String, owner: PsiModifierList): PsiAnnotation? fun findSpecialAnnotation(annotationsBox: GranularAnnotationsBox, qualifiedName: String, owner: PsiElement): PsiAnnotation?
/** /**
* Adds a new annotation with [qualifier] name to [currentRawAnnotations] and [foundQualifiers] if not already present * Adds a new annotation with [qualifier] name to [currentRawAnnotations] and [foundQualifiers] if not already present
@@ -53,7 +53,7 @@ internal sealed interface AdditionalAnnotationsProvider {
qualifier: String, qualifier: String,
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList, owner: PsiElement,
) { ) {
val isNewQualifier = foundQualifiers.add(qualifier) val isNewQualifier = foundQualifiers.add(qualifier)
if (!isNewQualifier) return if (!isNewQualifier) return
@@ -64,6 +64,6 @@ internal sealed interface AdditionalAnnotationsProvider {
fun createSimpleAnnotationIfMatches( fun createSimpleAnnotationIfMatches(
qualifier: String, qualifier: String,
expectedQualifier: String, expectedQualifier: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = if (qualifier == expectedQualifier) SymbolLightSimpleAnnotation(expectedQualifier, owner) else null ): PsiAnnotation? = if (qualifier == expectedQualifier) SymbolLightSimpleAnnotation(expectedQualifier, owner) else null
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
/** /**
* This class is used as a proxy for [com.intellij.psi.PsiAnnotationOwner]. * This class is used as a proxy for [com.intellij.psi.PsiAnnotationOwner].
@@ -18,7 +18,7 @@ import com.intellij.psi.PsiModifierList
* @see org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightModifierList * @see org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightModifierList
*/ */
internal sealed interface AnnotationsBox { internal sealed interface AnnotationsBox {
fun annotationsArray(owner: PsiModifierList): Array<PsiAnnotation> fun annotationsArray(owner: PsiElement): Array<PsiAnnotation>
fun findAnnotation(owner: PsiModifierList, qualifiedName: String): PsiAnnotation? fun findAnnotation(owner: PsiElement, qualifiedName: String): PsiAnnotation?
fun hasAnnotation(owner: PsiModifierList, qualifiedName: String): Boolean = findAnnotation(owner, qualifiedName) != null fun hasAnnotation(owner: PsiElement, qualifiedName: String): Boolean = findAnnotation(owner, qualifiedName) != null
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
internal class CollectionAdditionalAnnotationsProvider( internal class CollectionAdditionalAnnotationsProvider(
private val additionalAnnotationQualifiers: Collection<String>, private val additionalAnnotationQualifiers: Collection<String>,
@@ -16,7 +16,7 @@ internal class CollectionAdditionalAnnotationsProvider(
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList, owner: PsiElement,
) { ) {
additionalAnnotationQualifiers.forEach { qualifiedName -> additionalAnnotationQualifiers.forEach { qualifiedName ->
addSimpleAnnotationIfMissing(qualifiedName, currentRawAnnotations, foundQualifiers, owner) addSimpleAnnotationIfMissing(qualifiedName, currentRawAnnotations, foundQualifiers, owner)
@@ -26,7 +26,7 @@ internal class CollectionAdditionalAnnotationsProvider(
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? { ): PsiAnnotation? {
if (qualifiedName !in additionalAnnotationQualifiers) return null if (qualifiedName !in additionalAnnotationQualifiers) return null
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
internal class CompositeAdditionalAnnotationsProvider(val providers: List<AdditionalAnnotationsProvider>) : AdditionalAnnotationsProvider { internal class CompositeAdditionalAnnotationsProvider(val providers: List<AdditionalAnnotationsProvider>) : AdditionalAnnotationsProvider {
constructor(vararg providers: AdditionalAnnotationsProvider) : this(providers.toList()) constructor(vararg providers: AdditionalAnnotationsProvider) : this(providers.toList())
@@ -14,7 +14,7 @@ internal class CompositeAdditionalAnnotationsProvider(val providers: List<Additi
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList, owner: PsiElement,
) { ) {
providers.forEach { provider -> providers.forEach { provider ->
provider.addAllAnnotations(currentRawAnnotations, foundQualifiers, owner) provider.addAllAnnotations(currentRawAnnotations, foundQualifiers, owner)
@@ -24,7 +24,7 @@ internal class CompositeAdditionalAnnotationsProvider(val providers: List<Additi
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = providers.firstNotNullOfOrNull { provider -> provider.findSpecialAnnotation(annotationsBox, qualifiedName, owner) } ): PsiAnnotation? = providers.firstNotNullOfOrNull { provider -> provider.findSpecialAnnotation(annotationsBox, qualifiedName, owner) }
override fun isSpecialQualifier(qualifiedName: String): Boolean = providers.any { it.isSpecialQualifier(qualifiedName) } override fun isSpecialQualifier(qualifiedName: String): Boolean = providers.any { it.isSpecialQualifier(qualifiedName) }
@@ -1,22 +1,22 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.light.classes.symbol.toArrayIfNotEmptyOrDefault import org.jetbrains.kotlin.light.classes.symbol.toArrayIfNotEmptyOrDefault
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
internal class ComputeAllAtOnceAnnotationsBox( internal class ComputeAllAtOnceAnnotationsBox(
private val annotationsComputer: (PsiModifierList) -> Collection<PsiAnnotation>, private val annotationsComputer: (PsiElement) -> Collection<PsiAnnotation>,
) : AnnotationsBox { ) : AnnotationsBox {
@Volatile @Volatile
private var cachedAnnotations: Collection<PsiAnnotation>? = null private var cachedAnnotations: Collection<PsiAnnotation>? = null
private fun getOrComputeAnnotations(owner: PsiModifierList): Collection<PsiAnnotation> { private fun getOrComputeAnnotations(owner: PsiElement): Collection<PsiAnnotation> {
cachedAnnotations?.let { return it } cachedAnnotations?.let { return it }
val nonCachedAnnotations = annotationsComputer(owner) val nonCachedAnnotations = annotationsComputer(owner)
@@ -26,11 +26,11 @@ internal class ComputeAllAtOnceAnnotationsBox(
} }
override fun annotationsArray( override fun annotationsArray(
owner: PsiModifierList, owner: PsiElement,
): Array<PsiAnnotation> = getOrComputeAnnotations(owner).toArrayIfNotEmptyOrDefault(PsiAnnotation.EMPTY_ARRAY) ): Array<PsiAnnotation> = getOrComputeAnnotations(owner).toArrayIfNotEmptyOrDefault(PsiAnnotation.EMPTY_ARRAY)
override fun findAnnotation( override fun findAnnotation(
owner: PsiModifierList, owner: PsiElement,
qualifiedName: String, qualifiedName: String,
): PsiAnnotation? = getOrComputeAnnotations(owner).find { it.qualifiedName == qualifiedName } ): PsiAnnotation? = getOrComputeAnnotations(owner).find { it.qualifiedName == qualifiedName }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -7,14 +7,14 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiDocCommentOwner import com.intellij.psi.PsiDocCommentOwner
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames
internal object DeprecatedAdditionalAnnotationsProvider : AdditionalAnnotationsProvider { internal object DeprecatedAdditionalAnnotationsProvider : AdditionalAnnotationsProvider {
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList owner: PsiElement
) { ) {
if ((owner.parent as? PsiDocCommentOwner)?.isDeprecated == true) { if ((owner.parent as? PsiDocCommentOwner)?.isDeprecated == true) {
addSimpleAnnotationIfMissing(JvmAnnotationNames.DEPRECATED_ANNOTATION.asString(), currentRawAnnotations, foundQualifiers, owner) addSimpleAnnotationIfMissing(JvmAnnotationNames.DEPRECATED_ANNOTATION.asString(), currentRawAnnotations, foundQualifiers, owner)
@@ -26,7 +26,7 @@ internal object DeprecatedAdditionalAnnotationsProvider : AdditionalAnnotationsP
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList owner: PsiElement
): PsiAnnotation? = if ((owner.parent as? PsiDocCommentOwner)?.isDeprecated == true) ): PsiAnnotation? = if ((owner.parent as? PsiDocCommentOwner)?.isDeprecated == true)
createSimpleAnnotationIfMatches( createSimpleAnnotationIfMatches(
qualifier = qualifiedName, qualifier = qualifiedName,
@@ -1,24 +1,24 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
internal object EmptyAdditionalAnnotationsProvider : AdditionalAnnotationsProvider { internal object EmptyAdditionalAnnotationsProvider : AdditionalAnnotationsProvider {
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList, owner: PsiElement,
) = Unit ) = Unit
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = null ): PsiAnnotation? = null
override fun isSpecialQualifier(qualifiedName: String): Boolean = false override fun isSpecialQualifier(qualifiedName: String): Boolean = false
@@ -1,14 +1,14 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
internal object EmptyAnnotationsBox : AnnotationsBox { internal object EmptyAnnotationsBox : AnnotationsBox {
override fun annotationsArray(owner: PsiModifierList): Array<PsiAnnotation> = PsiAnnotation.EMPTY_ARRAY override fun annotationsArray(owner: PsiElement): Array<PsiAnnotation> = PsiAnnotation.EMPTY_ARRAY
override fun findAnnotation(owner: PsiModifierList, qualifiedName: String): PsiAnnotation? = null override fun findAnnotation(owner: PsiElement, qualifiedName: String): PsiAnnotation? = null
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.light.classes.symbol.toArrayIfNotEmptyOrDefault import org.jetbrains.kotlin.light.classes.symbol.toArrayIfNotEmptyOrDefault
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.JvmStandardClassIds import org.jetbrains.kotlin.name.JvmStandardClassIds
@@ -22,7 +22,7 @@ internal class GranularAnnotationsBox(
@Volatile @Volatile
private var cachedAnnotations: Collection<PsiAnnotation>? = null private var cachedAnnotations: Collection<PsiAnnotation>? = null
private fun getOrComputeCachedAnnotations(owner: PsiModifierList): Collection<PsiAnnotation> { private fun getOrComputeCachedAnnotations(owner: PsiElement): Collection<PsiAnnotation> {
cachedAnnotations?.let { return it } cachedAnnotations?.let { return it }
val annotations = annotationsProvider.annotationInfos().mapNotNullTo(SmartList<PsiAnnotation>()) { applicationInfo -> val annotations = annotationsProvider.annotationInfos().mapNotNullTo(SmartList<PsiAnnotation>()) { applicationInfo ->
@@ -40,16 +40,16 @@ internal class GranularAnnotationsBox(
return getOrComputeCachedAnnotations(owner) return getOrComputeCachedAnnotations(owner)
} }
override fun annotationsArray(owner: PsiModifierList): Array<PsiAnnotation> { override fun annotationsArray(owner: PsiElement): Array<PsiAnnotation> {
return getOrComputeCachedAnnotations(owner).toArrayIfNotEmptyOrDefault(PsiAnnotation.EMPTY_ARRAY) return getOrComputeCachedAnnotations(owner).toArrayIfNotEmptyOrDefault(PsiAnnotation.EMPTY_ARRAY)
} }
override fun findAnnotation( override fun findAnnotation(
owner: PsiModifierList, owner: PsiElement,
qualifiedName: String, qualifiedName: String,
): PsiAnnotation? = findAnnotation(owner, qualifiedName, withAdditionalAnnotations = true) ): PsiAnnotation? = findAnnotation(owner, qualifiedName, withAdditionalAnnotations = true)
fun findAnnotation(owner: PsiModifierList, qualifiedName: String, withAdditionalAnnotations: Boolean): PsiAnnotation? { fun findAnnotation(owner: PsiElement, qualifiedName: String, withAdditionalAnnotations: Boolean): PsiAnnotation? {
if (!annotationFilter.isAllowed(qualifiedName)) return null if (!annotationFilter.isAllowed(qualifiedName)) return null
cachedAnnotations?.let { annotations -> cachedAnnotations?.let { annotations ->
@@ -68,7 +68,7 @@ internal class GranularAnnotationsBox(
return getOrComputeCachedAnnotations(owner).find { it.qualifiedName == qualifiedName } return getOrComputeCachedAnnotations(owner).find { it.qualifiedName == qualifiedName }
} }
override fun hasAnnotation(owner: PsiModifierList, qualifiedName: String): Boolean { override fun hasAnnotation(owner: PsiElement, qualifiedName: String): Boolean {
if (!annotationFilter.isAllowed(qualifiedName)) return false if (!annotationFilter.isAllowed(qualifiedName)) return false
cachedAnnotations?.let { annotations -> cachedAnnotations?.let { annotations ->
@@ -93,14 +93,14 @@ internal class GranularAnnotationsBox(
/** /**
* We can safety reduce resolve only for annotations without arguments * We can safety reduce resolve only for annotations without arguments
* *
* @see org.jetbrains.kotlin.fir.resolve.transformers.plugin.CompilerRequiredAnnotationsHelper * @see org.jetbrains.kotlin.fir.declarations.FirAnnotationsPlatformSpecificSupportComponent
*/ */
private val specialAnnotationsListWithSafeArgumentsResolve: Map<String, ClassId> = listOf( private val specialAnnotationsListWithSafeArgumentsResolve: Map<String, ClassId> = listOf(
JvmStandardClassIds.Annotations.JvmRecord, JvmStandardClassIds.Annotations.JvmRecord,
).associateBy { it.asFqNameString() } ).associateBy { it.asFqNameString() }
/** /**
* @see org.jetbrains.kotlin.fir.resolve.transformers.plugin.CompilerRequiredAnnotationsHelper * @see org.jetbrains.kotlin.fir.declarations.FirAnnotationsPlatformSpecificSupportComponent
*/ */
private val specialAnnotationsList: Map<String, ClassId> = listOf( private val specialAnnotationsList: Map<String, ClassId> = listOf(
StandardClassIds.Annotations.Deprecated, StandardClassIds.Annotations.Deprecated,
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames
@@ -15,7 +14,7 @@ internal object MethodAdditionalAnnotationsProvider : AdditionalAnnotationsProvi
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList, owner: PsiElement,
) { ) {
if (owner.parent.isMethodWithOverride()) { if (owner.parent.isMethodWithOverride()) {
addSimpleAnnotationIfMissing(JvmAnnotationNames.OVERRIDE_ANNOTATION.asString(), currentRawAnnotations, foundQualifiers, owner) addSimpleAnnotationIfMissing(JvmAnnotationNames.OVERRIDE_ANNOTATION.asString(), currentRawAnnotations, foundQualifiers, owner)
@@ -25,7 +24,7 @@ internal object MethodAdditionalAnnotationsProvider : AdditionalAnnotationsProvi
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? = if (owner.parent.isMethodWithOverride()) ): PsiAnnotation? = if (owner.parent.isMethodWithOverride())
createSimpleAnnotationIfMatches( createSimpleAnnotationIfMatches(
qualifier = qualifiedName, qualifier = qualifiedName,
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 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. * 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 package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.asJava.classes.lazyPub import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.light.classes.symbol.NullabilityType import org.jetbrains.kotlin.light.classes.symbol.NullabilityType
import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames
@@ -17,7 +17,7 @@ internal class NullabilityAnnotationsProvider(private val lazyNullabilityType: L
override fun addAllAnnotations( override fun addAllAnnotations(
currentRawAnnotations: MutableList<in PsiAnnotation>, currentRawAnnotations: MutableList<in PsiAnnotation>,
foundQualifiers: MutableSet<String>, foundQualifiers: MutableSet<String>,
owner: PsiModifierList owner: PsiElement
) { ) {
val qualifier = lazyNullabilityType.qualifier ?: return val qualifier = lazyNullabilityType.qualifier ?: return
addSimpleAnnotationIfMissing(qualifier, currentRawAnnotations, foundQualifiers, owner) addSimpleAnnotationIfMissing(qualifier, currentRawAnnotations, foundQualifiers, owner)
@@ -26,7 +26,7 @@ internal class NullabilityAnnotationsProvider(private val lazyNullabilityType: L
override fun findSpecialAnnotation( override fun findSpecialAnnotation(
annotationsBox: GranularAnnotationsBox, annotationsBox: GranularAnnotationsBox,
qualifiedName: String, qualifiedName: String,
owner: PsiModifierList, owner: PsiElement,
): PsiAnnotation? { ): PsiAnnotation? {
if (!qualifiedName.isNullOrNotNullQualifiedName) { if (!qualifiedName.isNullOrNotNullQualifiedName) {
return null return null
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotationParameterList import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue
import org.jetbrains.kotlin.asJava.classes.lazyPub import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.KtCallElement import org.jetbrains.kotlin.psi.KtCallElement
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtCallElement
internal open class SymbolLightJavaAnnotation( internal open class SymbolLightJavaAnnotation(
val originalLightAnnotation: SymbolLightLazyAnnotation, val originalLightAnnotation: SymbolLightLazyAnnotation,
private val javaQualifier: String, private val javaQualifier: String,
owner: PsiModifierList, owner: PsiElement,
private val argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue>, private val argumentsComputer: SymbolLightJavaAnnotation.() -> List<KtNamedAnnotationValue>,
) : SymbolLightAbstractAnnotation(owner) { ) : SymbolLightAbstractAnnotation(owner) {
override fun createReferenceInformationProvider(): ReferenceInformationProvider = ReferenceInformationHolder( override fun createReferenceInformationProvider(): ReferenceInformationProvider = ReferenceInformationHolder(
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotationParameterList import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.asJava.classes.lazyPub import org.jetbrains.kotlin.asJava.classes.lazyPub
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.psi.KtCallElement
internal class SymbolLightLazyAnnotation( internal class SymbolLightLazyAnnotation(
val annotationsProvider: AnnotationsProvider, val annotationsProvider: AnnotationsProvider,
private val annotationApplication: KtAnnotationApplication, private val annotationApplication: KtAnnotationApplication,
owner: PsiModifierList, owner: PsiElement,
) : SymbolLightAbstractAnnotation(owner) { ) : SymbolLightAbstractAnnotation(owner) {
init { init {
requireNotNull(annotationApplication.classId) requireNotNull(annotationApplication.classId)