-
Notifications
You must be signed in to change notification settings - Fork 99
/
WorkflowIdentifierType.kt
51 lines (44 loc) · 1.52 KB
/
WorkflowIdentifierType.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.squareup.workflow1
import kotlin.reflect.KClass
import kotlin.reflect.KType
/**
* Represents a subset of [KAnnotatedElement], namely [KClass] or [KType]. Used by the runtime to
* determine whether a [WorkflowIdentifier], and thus the [Workflow] it identifies, is serializable
* or not via the [Snapshot] mechanism.
*/
public sealed class WorkflowIdentifierType {
public abstract val typeName: String
/**
* A [WorkflowIdentifier] is snapshottable if its type is this [Snapshottable] class.
*
* @constructor
* @param typeName The qualified name of its corresponding [Workflow].
* @param kClass The [KClass] of the [Workflow] this helps identify.
*/
public data class Snapshottable(
override val typeName: String,
val kClass: KClass<*>? = null,
) : WorkflowIdentifierType() {
public constructor(kClass: KClass<*>) : this(
WorkflowIdentifierTypeNamer.uniqueName(kClass),
kClass
)
}
/**
* A [WorkflowIdentifier] is unsnapshottable if its type is this [Unsnapshottable] class.
*
* @constructor
* @param kType The [KType] of the [Workflow] this helps identify.
*/
public data class Unsnapshottable(val kType: KType) : WorkflowIdentifierType() {
init {
require(kType.classifier is KClass<*>) {
"Expected a KType with a KClass classifier, but was ${kType.classifier}"
}
}
override val typeName: String = kType.toString()
}
}
internal expect object WorkflowIdentifierTypeNamer {
public fun uniqueName(kClass: KClass<*>): String
}