Add @Deprecated annotation to a synthetic $serializer class
in K2 so it matches K1 behavior. Deprecation is required, so the declaration will not be visible to user in completion in the IDE. #KT-65757 Fixed
This commit is contained in:
committed by
Space Team
parent
0df3a37303
commit
dbb7ab1760
+6
-7
@@ -11,10 +11,8 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
|
||||
import org.jetbrains.kotlin.fir.copy
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy
|
||||
import org.jetbrains.kotlin.fir.declarations.origin
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
|
||||
import org.jetbrains.kotlin.fir.extensions.*
|
||||
import org.jetbrains.kotlin.fir.plugin.*
|
||||
@@ -278,6 +276,8 @@ class SerializationFirResolveExtension(session: FirSession) : FirDeclarationGene
|
||||
val hasTypeParams = owner.typeParameterSymbols.isNotEmpty()
|
||||
val serializerKind = if (hasTypeParams) ClassKind.CLASS else ClassKind.OBJECT
|
||||
val serializerFirClass = createNestedClass(owner, SerialEntityNames.SERIALIZER_CLASS_NAME, SerializationPluginKey, serializerKind) {
|
||||
modality = Modality.FINAL
|
||||
|
||||
for (parameter in owner.typeParameterSymbols) {
|
||||
typeParameter(parameter.name)
|
||||
}
|
||||
@@ -292,11 +292,10 @@ class SerializationFirResolveExtension(session: FirSession) : FirDeclarationGene
|
||||
isNullable = false
|
||||
)
|
||||
}
|
||||
}.apply {
|
||||
excludeFromJsExport()
|
||||
markAsDeprecatedHidden()
|
||||
}
|
||||
// TODO: add deprecate hidden
|
||||
// serializerFirClass.replaceAnnotations(listOf(Annotations.create(listOf(KSerializerDescriptorResolver.createDeprecatedHiddenAnnotation(thisDescriptor.module)))))
|
||||
serializerFirClass.excludeFromJsExport()
|
||||
|
||||
return serializerFirClass.symbol
|
||||
}
|
||||
|
||||
|
||||
+33
-1
@@ -8,8 +8,9 @@ package org.jetbrains.kotlinx.serialization.compiler.fir
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.deserialization.toQualifiedPropertyAccessExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.*
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.predicateBasedProvider
|
||||
import org.jetbrains.kotlin.fir.moduleData
|
||||
@@ -27,9 +28,11 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.platform.isJs
|
||||
import org.jetbrains.kotlin.platform.isWasm
|
||||
import org.jetbrains.kotlin.platform.konan.isNative
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlinx.serialization.compiler.fir.services.dependencySerializationInfoProvider
|
||||
import org.jetbrains.kotlinx.serialization.compiler.resolve.SerialEntityNames
|
||||
@@ -280,3 +283,32 @@ fun FirDeclaration.excludeFromJsExport() {
|
||||
|
||||
replaceAnnotations(annotations + jsExportIgnoreAnnotationCall)
|
||||
}
|
||||
|
||||
context(FirExtension)
|
||||
fun createDeprecatedHiddenAnnotation(): FirAnnotation = buildAnnotation {
|
||||
val deprecatedAnno =
|
||||
session.symbolProvider.getClassLikeSymbolByClassId(StandardClassIds.Annotations.Deprecated) as FirRegularClassSymbol
|
||||
|
||||
annotationTypeRef = deprecatedAnno.defaultType().toFirResolvedTypeRef()
|
||||
|
||||
argumentMapping = buildAnnotationArgumentMapping {
|
||||
mapping[Name.identifier("message")] = buildLiteralExpression(
|
||||
null,
|
||||
ConstantValueKind.String,
|
||||
"This synthesized declaration should not be used directly",
|
||||
setType = true
|
||||
)
|
||||
|
||||
// It has nothing to do with enums deserialization, but it is simply easier to build it this way.
|
||||
mapping[Name.identifier("level")] = buildEnumEntryDeserializedAccessExpression {
|
||||
enumClassId = StandardClassIds.DeprecationLevel
|
||||
enumEntryName = Name.identifier("HIDDEN")
|
||||
}.toQualifiedPropertyAccessExpression(session)
|
||||
}
|
||||
}
|
||||
|
||||
context(FirExtension)
|
||||
fun FirClassLikeDeclaration.markAsDeprecatedHidden() {
|
||||
replaceAnnotations(annotations + listOf(createDeprecatedHiddenAnnotation()))
|
||||
replaceDeprecationsProvider(this.getDeprecationsProvider(session))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user