[AA] Fix conversion of annotation values
This commit is contained in:
committed by
Space Team
parent
40a4845541
commit
7700484a16
+6
@@ -109,6 +109,12 @@ public class Fe10IdeNormalAnalysisSourceModuleAnalysisApiAnnotationsOnDeclaratio
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/onTypeAlias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsignedParameter.kt")
|
||||
public void testUnsignedParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/unsignedParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargComplexParameter.kt")
|
||||
public void testVarargComplexParameter() throws Exception {
|
||||
|
||||
+23
-4
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.fir.evaluate
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.*
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtConstantValueFactory
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtConstantEvaluationMode
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -23,8 +23,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeErrorType
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
@@ -44,7 +43,27 @@ internal object FirAnnotationValueConverter {
|
||||
}
|
||||
|
||||
private fun <T> FirConstExpression<T>.convertConstantExpression(): KtConstantAnnotationValue? {
|
||||
val constantValue = KtConstantValueFactory.createConstantValue(value, psi as? KtElement) ?: return null
|
||||
val expression = psi as? KtElement
|
||||
val type = (typeRef as? FirResolvedTypeRef)?.type
|
||||
val constantValue = when {
|
||||
value == null -> KtConstantValue.KtNullConstantValue(expression)
|
||||
type == null -> return null
|
||||
type.isBoolean -> KtConstantValue.KtBooleanConstantValue(value as Boolean, expression)
|
||||
type.isChar -> KtConstantValue.KtCharConstantValue((value as? Char) ?: (value as Number).toInt().toChar(), expression)
|
||||
type.isByte -> KtConstantValue.KtByteConstantValue((value as Number).toByte(), expression)
|
||||
type.isUByte -> KtConstantValue.KtUnsignedByteConstantValue((value as Number).toByte().toUByte(), expression)
|
||||
type.isShort -> KtConstantValue.KtShortConstantValue((value as Number).toShort(), expression)
|
||||
type.isUShort -> KtConstantValue.KtUnsignedShortConstantValue((value as Number).toShort().toUShort(), expression)
|
||||
type.isInt -> KtConstantValue.KtIntConstantValue((value as Number).toInt(), expression)
|
||||
type.isUInt -> KtConstantValue.KtUnsignedIntConstantValue((value as Number).toInt().toUInt(), expression)
|
||||
type.isLong -> KtConstantValue.KtLongConstantValue((value as Number).toLong(), expression)
|
||||
type.isULong -> KtConstantValue.KtUnsignedLongConstantValue((value as Number).toLong().toULong(), expression)
|
||||
type.isString -> KtConstantValue.KtStringConstantValue(value.toString(), expression)
|
||||
type.isFloat -> KtConstantValue.KtFloatConstantValue((value as Number).toFloat(), expression)
|
||||
type.isDouble -> KtConstantValue.KtDoubleConstantValue((value as Number).toDouble(), expression)
|
||||
else -> return null
|
||||
}
|
||||
|
||||
return KtConstantAnnotationValue(constantValue)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -109,6 +109,12 @@ public class FirIdeDependentAnalysisSourceModuleAnalysisApiAnnotationsOnDeclarat
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/onTypeAlias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsignedParameter.kt")
|
||||
public void testUnsignedParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/unsignedParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargComplexParameter.kt")
|
||||
public void testVarargComplexParameter() throws Exception {
|
||||
|
||||
+6
@@ -109,6 +109,12 @@ public class FirIdeNormalAnalysisSourceModuleAnalysisApiAnnotationsOnDeclaration
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/onTypeAlias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsignedParameter.kt")
|
||||
public void testUnsignedParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/unsignedParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargComplexParameter.kt")
|
||||
public void testVarargComplexParameter() throws Exception {
|
||||
|
||||
+6
@@ -109,6 +109,12 @@ public class FirStandaloneNormalAnalysisSourceModuleAnalysisApiAnnotationsOnDecl
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/onTypeAlias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsignedParameter.kt")
|
||||
public void testUnsignedParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/annotations/annotationsOnDeclaration/direct/unsignedParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargComplexParameter.kt")
|
||||
public void testVarargComplexParameter() throws Exception {
|
||||
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
annotation class A(vararg val xs: ULong)
|
||||
|
||||
@A(1234u, 18446744073709551615u)
|
||||
fun fo<caret>o(): Int = 42
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
KtDeclaration: KtNamedFunction foo
|
||||
annotations: [
|
||||
A(xs = [1234uL, 18446744073709551615uL])
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
@@ -30,6 +30,8 @@ val ConeKotlinType.isString: Boolean get() = isBuiltinType(StandardClassIds.Stri
|
||||
|
||||
val ConeKotlinType.isEnum: Boolean get() = isBuiltinType(StandardClassIds.Enum, false)
|
||||
|
||||
val ConeKotlinType.isUByte: Boolean get() = isBuiltinType(StandardClassIds.UByte, false)
|
||||
val ConeKotlinType.isUShort: Boolean get() = isBuiltinType(StandardClassIds.UShort, false)
|
||||
val ConeKotlinType.isUInt: Boolean get() = isBuiltinType(StandardClassIds.UInt, false)
|
||||
val ConeKotlinType.isULong: Boolean get() = isBuiltinType(StandardClassIds.ULong, false)
|
||||
val ConeKotlinType.isPrimitiveOrNullablePrimitive: Boolean get() = isAnyOfBuiltinType(StandardClassIds.primitiveTypes)
|
||||
|
||||
compiler/testData/asJava/lightClasses/lightClassByFqName/compilationErrors/WrongAnnotations.fir.java
Vendored
+1
-1
@@ -14,7 +14,7 @@ public final class A /* A*/ {
|
||||
@kotlin.jvm.JvmName(name = "realName")
|
||||
public final void realName();// realName()
|
||||
|
||||
@kotlin.jvm.JvmName(name = 1L)
|
||||
@kotlin.jvm.JvmName(name = 1)
|
||||
public final void f2();// f2()
|
||||
|
||||
@kotlin.jvm.JvmOverloads()
|
||||
|
||||
+4
-4
@@ -14,14 +14,14 @@ public abstract @interface Ann /* Ann*/ {
|
||||
}
|
||||
|
||||
public abstract interface Base /* Base*/ {
|
||||
@Ann(x = 1L, y = "134", z = java.lang.String.class, e = {int.class, double.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("243"), SimpleAnn("4324")})
|
||||
public abstract void foo(@Ann(x = 2L, y = "324", z = Ann.class, e = {byte.class, Base.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("687"), SimpleAnn("78")}) @org.jetbrains.annotations.NotNull() java.lang.String);// foo(java.lang.String)
|
||||
@Ann(x = 1, y = "134", z = java.lang.String.class, e = {int.class, double.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("243"), SimpleAnn("4324")})
|
||||
public abstract void foo(@Ann(x = 2, y = "324", z = Ann.class, e = {byte.class, Base.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("687"), SimpleAnn("78")}) @org.jetbrains.annotations.NotNull() java.lang.String);// foo(java.lang.String)
|
||||
}
|
||||
|
||||
public final class Derived /* Derived*/ implements Base {
|
||||
@Ann(x = 1L, y = "134", z = java.lang.String.class, e = {int.class, double.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("243"), SimpleAnn("4324")})
|
||||
@Ann(x = 1, y = "134", z = java.lang.String.class, e = {int.class, double.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("243"), SimpleAnn("4324")})
|
||||
@java.lang.Override()
|
||||
public void foo(@Ann(x = 2L, y = "324", z = Ann.class, e = {byte.class, Base.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("687"), SimpleAnn("78")}) @org.jetbrains.annotations.NotNull() java.lang.String);// foo(java.lang.String)
|
||||
public void foo(@Ann(x = 2, y = "324", z = Ann.class, e = {byte.class, Base.class}, depr = kotlin.DeprecationLevel.WARNING, t = {SimpleAnn("687"), SimpleAnn("78")}) @org.jetbrains.annotations.NotNull() java.lang.String);// foo(java.lang.String)
|
||||
|
||||
public Derived(@org.jetbrains.annotations.NotNull() Base);// .ctor(Base)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user