• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization
6 
7 import kotlinx.serialization.descriptors.*
8 
9 @SerialInfo
10 @Target(AnnotationTarget.PROPERTY)
11 annotation class Id(val id: Int)
12 
getSerialIdnull13 public fun getSerialId(desc: SerialDescriptor, index: Int): Int?
14         = desc.findAnnotation<Id>(index)?.id
15 
16 public inline fun <reified A: Annotation> SerialDescriptor.findAnnotation(elementIndex: Int): A? {
17     val candidates = getElementAnnotations(elementIndex).filterIsInstance<A>()
18     return when (candidates.size) {
19         0 -> null
20         1 -> candidates[0]
21         else -> throw IllegalStateException("There are duplicate annotations of type ${A::class} in the descriptor $this")
22     }
23 }
24