[SLC] introduce SymbolLightEmptyAnnotationParameterList

^KT-56046
This commit is contained in:
Dmitrii Gridin
2023-01-26 15:41:12 +01:00
committed by Space Team
parent aa9e7444c9
commit 48ed72c391
6 changed files with 51 additions and 15 deletions
@@ -0,0 +1,29 @@
/*
* 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.PsiAnnotationParameterList
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import org.jetbrains.kotlin.psi.KtElement
internal sealed class SymbolLightAbstractAnnotationParameterList(
parent: SymbolLightAbstractAnnotation,
) : KtLightElementBase(parent), PsiAnnotationParameterList {
override val kotlinOrigin: KtElement?
get() = (parent as SymbolLightAbstractAnnotation).kotlinOrigin?.valueArgumentList
override fun equals(other: Any?): Boolean = other === this || other is SymbolLightLazyAnnotationParameterList && other.parent == parent
override fun hashCode(): Int = parent.hashCode()
}
internal fun SymbolLightAbstractAnnotation.symbolLightAnnotationParameterList(
arguments: List<KtNamedAnnotationValue> = emptyList(),
): SymbolLightAbstractAnnotationParameterList = if (arguments.isNotEmpty()) {
SymbolLightLazyAnnotationParameterList(this, lazyOf(arguments))
} else {
SymbolLightEmptyAnnotationParameterList(this)
}
@@ -19,7 +19,7 @@ internal class SymbolLightAnnotationForAnnotationCall(
parent: PsiModifierList,
) : SymbolLightAbstractAnnotation(parent) {
private val _parameterList: PsiAnnotationParameterList by lazyPub {
SymbolLightLazyAnnotationParameterList(this, lazyOf(annotationCall.arguments))
symbolLightAnnotationParameterList(annotationCall.arguments)
}
override fun getParameterList(): PsiAnnotationParameterList = _parameterList
@@ -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.PsiNameValuePair
internal class SymbolLightEmptyAnnotationParameterList(
parent: SymbolLightAbstractAnnotation,
) : SymbolLightAbstractAnnotationParameterList(parent) {
override fun getAttributes(): Array<PsiNameValuePair> = PsiNameValuePair.EMPTY_ARRAY
}
@@ -64,7 +64,11 @@ internal class SymbolLightLazyAnnotation private constructor(
override fun getQualifiedName(): String = fqName.asString()
private val _parameterList: PsiAnnotationParameterList by lazyPub {
SymbolLightLazyAnnotationParameterList(this, lazyPub { annotationApplication.value.arguments })
if (annotationOverview?.hasArguments == true || !specialAnnotationApplication?.arguments.isNullOrEmpty()) {
SymbolLightLazyAnnotationParameterList(this, lazyPub { annotationApplication.value.arguments })
} else {
SymbolLightEmptyAnnotationParameterList(this)
}
}
override fun getParameterList(): PsiAnnotationParameterList = _parameterList
@@ -5,21 +5,14 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiNameValuePair
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import org.jetbrains.kotlin.psi.KtElement
internal class SymbolLightLazyAnnotationParameterList(
parent: SymbolLightAbstractAnnotation,
private val lazyArguments: Lazy<List<KtNamedAnnotationValue>>,
) : KtLightElementBase(parent),
PsiAnnotationParameterList {
override val kotlinOrigin: KtElement?
get() = (parent as SymbolLightAbstractAnnotation).kotlinOrigin?.valueArgumentList
) : SymbolLightAbstractAnnotationParameterList(parent) {
private val _attributes: Array<PsiNameValuePair> by lazyPub {
val attributes = lazyArguments.value.map {
SymbolNameValuePairForAnnotationArgument(it, this)
@@ -29,7 +22,4 @@ internal class SymbolLightLazyAnnotationParameterList(
}
override fun getAttributes(): Array<PsiNameValuePair> = _attributes
override fun equals(other: Any?): Boolean = other === this || other is SymbolLightLazyAnnotationParameterList && other.parent == parent
override fun hashCode(): Int = parent.hashCode()
}
@@ -29,9 +29,8 @@ internal class SymbolLightSimpleAnnotation(
override fun hashCode(): Int = fqName.hashCode()
private val _parameterList: PsiAnnotationParameterList by lazyPub {
SymbolLightLazyAnnotationParameterList(this, lazyOf(arguments))
symbolLightAnnotationParameterList(arguments)
}
override fun getParameterList(): PsiAnnotationParameterList = _parameterList
}