Split ContextualSerialization annotation in two
This commit is contained in:
+6
-1
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -38,6 +38,11 @@ abstract class AbstractSerialGenerator(val bindingContext: BindingContext, val c
|
||||
getKClassListFromFileAnnotation(
|
||||
SerializationAnnotations.contextualFqName,
|
||||
currentDeclaration
|
||||
).plus(
|
||||
getKClassListFromFileAnnotation(
|
||||
SerializationAnnotations.contextualOnFileFqName,
|
||||
currentDeclaration
|
||||
)
|
||||
).toSet()
|
||||
}
|
||||
|
||||
|
||||
+4
-15
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlinx.serialization.compiler.backend.common
|
||||
@@ -118,7 +107,7 @@ fun analyzeSpecialSerializers(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
annotations: Annotations
|
||||
): ClassDescriptor? = when {
|
||||
annotations.hasAnnotation(SerializationAnnotations.contextualFqName) ->
|
||||
annotations.hasAnnotation(SerializationAnnotations.contextualFqName) || annotations.hasAnnotation(SerializationAnnotations.contextualOnPropertyFqName) ->
|
||||
moduleDescriptor.getClassFromSerializationPackage(SpecialBuiltins.contextSerializer)
|
||||
// can be annotation on type usage, e.g. List<@Polymorphic Any>
|
||||
annotations.hasAnnotation(SerializationAnnotations.polymorphicFqName) ->
|
||||
@@ -147,7 +136,7 @@ fun AbstractSerialGenerator.findTypeSerializerOrContext(
|
||||
if (kType.isTypeParameter()) return null
|
||||
return findTypeSerializerOrContextUnchecked(module, kType) ?: throw CompilationException(
|
||||
"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,
|
||||
sourceElement
|
||||
)
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ object SerializationPluginErrorsRendering : DefaultErrorMessages.Extension {
|
||||
MAP.put(
|
||||
SerializationErrors.SERIALIZER_NOT_FOUND,
|
||||
"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
|
||||
)
|
||||
MAP.put(
|
||||
|
||||
+3
-1
@@ -26,7 +26,9 @@ object SerializationAnnotations {
|
||||
internal val serialTransientFqName = FqName("kotlinx.serialization.Transient")
|
||||
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 additionalSerializersFqName = FqName("kotlinx.serialization.UseSerializers")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user