KT-62560 [SLC] Fix handling of empty varargs in annotations
This commit is contained in:
committed by
Space Team
parent
4f5926a88f
commit
03ed1d1d31
+4
-5
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiModifierList
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
@@ -39,10 +40,8 @@ internal class SymbolLightLazyAnnotation(
|
||||
override fun getQualifiedName(): String = fqName.asString()
|
||||
|
||||
private val _parameterList: PsiAnnotationParameterList by lazyPub {
|
||||
if (annotationApplication.isCallWithArguments) {
|
||||
symbolLightAnnotationParameterList { annotationApplicationWithArgumentsInfo.value.arguments }
|
||||
} else {
|
||||
symbolLightAnnotationParameterList()
|
||||
symbolLightAnnotationParameterList {
|
||||
annotationApplicationWithArgumentsInfo.value.normalizedArguments()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +58,4 @@ internal class SymbolLightLazyAnnotation(
|
||||
other.parent == parent
|
||||
|
||||
override fun hashCode(): Int = fqName.hashCode()
|
||||
}
|
||||
}
|
||||
+19
-3
@@ -199,14 +199,14 @@ internal fun KtAnnotationValue.toAnnotationMemberValue(parent: PsiElement): PsiA
|
||||
values.mapNotNull { element -> element.toAnnotationMemberValue(arrayLiteralParent) }
|
||||
}
|
||||
|
||||
is KtAnnotationApplicationValue ->
|
||||
is KtAnnotationApplicationValue -> {
|
||||
SymbolLightSimpleAnnotation(
|
||||
fqName = annotationValue.classId?.asFqNameString(),
|
||||
parent = parent,
|
||||
arguments = annotationValue.arguments,
|
||||
arguments = annotationValue.normalizedArguments(),
|
||||
kotlinOrigin = annotationValue.psi,
|
||||
)
|
||||
|
||||
}
|
||||
is KtConstantAnnotationValue -> {
|
||||
constantValue.createPsiExpression(parent)?.let {
|
||||
when (it) {
|
||||
@@ -221,6 +221,22 @@ internal fun KtAnnotationValue.toAnnotationMemberValue(parent: PsiElement): PsiA
|
||||
KtUnsupportedAnnotationValue -> null
|
||||
}
|
||||
|
||||
internal fun KtAnnotationApplicationWithArgumentsInfo.normalizedArguments(): List<KtNamedAnnotationValue> {
|
||||
val args = arguments
|
||||
val ctorSymbolPointer = constructorSymbolPointer ?: return args
|
||||
val element = psi ?: return args // May work incorrectly. See KT-63568
|
||||
|
||||
return analyzeForLightClasses(element) {
|
||||
val constructorSymbol = ctorSymbolPointer.restoreSymbolOrThrowIfDisposed()
|
||||
val params = constructorSymbol.valueParameters
|
||||
val missingVarargParameterName =
|
||||
params.singleOrNull { it.isVararg && !it.hasDefaultValue }?.name?.takeIf { name -> args.none { it.name == name } }
|
||||
if (missingVarargParameterName == null) args
|
||||
else args + KtNamedAnnotationValue(missingVarargParameterName, KtArrayAnnotationValue(emptyList(), null))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun KtEnumEntryAnnotationValue.asPsiReferenceExpression(parent: PsiElement): SymbolPsiReference? {
|
||||
val fqName = this.callableId?.asSingleFqName()?.asString() ?: return null
|
||||
val psiReference = parent.project.withElementFactorySafe {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@kotlin.Deprecated(message = "", replaceWith = @kotlin.ReplaceWith(expression = ""), level = kotlin.DeprecationLevel.ERROR)
|
||||
@kotlin.Deprecated(message = "", replaceWith = @kotlin.ReplaceWith(expression = "", imports = {}), level = kotlin.DeprecationLevel.ERROR)
|
||||
public final class MyClass /* MyClass*/ {
|
||||
public MyClass();// .ctor()
|
||||
}
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class SymbolLightClassesByPsiForLibraryTestGenerated extends AbstractSymb
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithSetParamPropertyModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationWithVaragArguments.kt")
|
||||
public void testAnnotationWithVaragArguments() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithVaragArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class SymbolLightClassesEqualityByPsiForLibraryTestGenerated extends Abst
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithSetParamPropertyModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationWithVaragArguments.kt")
|
||||
public void testAnnotationWithVaragArguments() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithVaragArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class SymbolLightClassesParentingByPsiForLibraryTestGenerated extends Abs
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithSetParamPropertyModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationWithVaragArguments.kt")
|
||||
public void testAnnotationWithVaragArguments() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithVaragArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class SymbolLightClassesByPsiForSourceTestGenerated extends AbstractSymbo
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithSetParamPropertyModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationWithVaragArguments.kt")
|
||||
public void testAnnotationWithVaragArguments() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithVaragArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class SymbolLightClassesEqualityByPsiForSourceTestGenerated extends Abstr
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithSetParamPropertyModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationWithVaragArguments.kt")
|
||||
public void testAnnotationWithVaragArguments() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithVaragArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class SymbolLightClassesParentingByPsiForSourceTestGenerated extends Abst
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithSetParamPropertyModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationWithVaragArguments.kt")
|
||||
public void testAnnotationWithVaragArguments() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/annotationWithVaragArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotations.kt")
|
||||
public void testAnnotations() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user