Split ContextualSerialization annotation in two

This commit is contained in:
Leonid Startsev
2020-06-30 17:21:11 +03:00
parent 3d91c410e7
commit 6ef597a4ee
4 changed files with 14 additions and 18 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2020 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.
*/ */
@@ -38,6 +38,11 @@ abstract class AbstractSerialGenerator(val bindingContext: BindingContext, val c
getKClassListFromFileAnnotation( getKClassListFromFileAnnotation(
SerializationAnnotations.contextualFqName, SerializationAnnotations.contextualFqName,
currentDeclaration currentDeclaration
).plus(
getKClassListFromFileAnnotation(
SerializationAnnotations.contextualOnFileFqName,
currentDeclaration
)
).toSet() ).toSet()
} }
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2020 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.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlinx.serialization.compiler.backend.common package org.jetbrains.kotlinx.serialization.compiler.backend.common
@@ -118,7 +107,7 @@ fun analyzeSpecialSerializers(
moduleDescriptor: ModuleDescriptor, moduleDescriptor: ModuleDescriptor,
annotations: Annotations annotations: Annotations
): ClassDescriptor? = when { ): ClassDescriptor? = when {
annotations.hasAnnotation(SerializationAnnotations.contextualFqName) -> annotations.hasAnnotation(SerializationAnnotations.contextualFqName) || annotations.hasAnnotation(SerializationAnnotations.contextualOnPropertyFqName) ->
moduleDescriptor.getClassFromSerializationPackage(SpecialBuiltins.contextSerializer) moduleDescriptor.getClassFromSerializationPackage(SpecialBuiltins.contextSerializer)
// can be annotation on type usage, e.g. List<@Polymorphic Any> // can be annotation on type usage, e.g. List<@Polymorphic Any>
annotations.hasAnnotation(SerializationAnnotations.polymorphicFqName) -> annotations.hasAnnotation(SerializationAnnotations.polymorphicFqName) ->
@@ -147,7 +136,7 @@ fun AbstractSerialGenerator.findTypeSerializerOrContext(
if (kType.isTypeParameter()) return null if (kType.isTypeParameter()) return null
return findTypeSerializerOrContextUnchecked(module, kType) ?: throw CompilationException( return findTypeSerializerOrContextUnchecked(module, kType) ?: throw CompilationException(
"Serializer for element of type $kType has not been found.\n" + "Serializer for element of type $kType has not been found.\n" +
"To use context serializer as fallback, explicitly annotate element with @ContextualSerialization", "To use context serializer as fallback, explicitly annotate element with @Contextual",
null, null,
sourceElement sourceElement
) )
@@ -48,7 +48,7 @@ object SerializationPluginErrorsRendering : DefaultErrorMessages.Extension {
MAP.put( MAP.put(
SerializationErrors.SERIALIZER_NOT_FOUND, SerializationErrors.SERIALIZER_NOT_FOUND,
"Serializer has not been found for type ''{0}''. " + "Serializer has not been found for type ''{0}''. " +
"To use context serializer as fallback, explicitly annotate type or property with @ContextualSerialization", "To use context serializer as fallback, explicitly annotate type or property with @Contextual",
Renderers.RENDER_TYPE_WITH_ANNOTATIONS Renderers.RENDER_TYPE_WITH_ANNOTATIONS
) )
MAP.put( MAP.put(
@@ -26,7 +26,9 @@ object SerializationAnnotations {
internal val serialTransientFqName = FqName("kotlinx.serialization.Transient") internal val serialTransientFqName = FqName("kotlinx.serialization.Transient")
internal val serialInfoFqName = FqName("kotlinx.serialization.SerialInfo") internal val serialInfoFqName = FqName("kotlinx.serialization.SerialInfo")
internal val contextualFqName = FqName("kotlinx.serialization.ContextualSerialization") internal val contextualFqName = FqName("kotlinx.serialization.ContextualSerialization") // this one is deprecated
internal val contextualOnFileFqName = FqName("kotlinx.serialization.UseContextualSerialization")
internal val contextualOnPropertyFqName = FqName("kotlinx.serialization.Contextual")
internal val polymorphicFqName = FqName("kotlinx.serialization.Polymorphic") internal val polymorphicFqName = FqName("kotlinx.serialization.Polymorphic")
internal val additionalSerializersFqName = FqName("kotlinx.serialization.UseSerializers") internal val additionalSerializersFqName = FqName("kotlinx.serialization.UseSerializers")
} }