Make property collection serializable (with runtime check)

This commit is contained in:
Ilya Chernikov
2018-09-06 12:52:50 +02:00
parent ae107339fd
commit ba2e08c014
4 changed files with 25 additions and 8 deletions
@@ -5,6 +5,7 @@
package kotlin.script.experimental.api
import java.io.Serializable
import kotlin.reflect.KClass
import kotlin.reflect.KType
@@ -13,9 +14,9 @@ import kotlin.reflect.KType
*/
class KotlinType private constructor(
val typeName: String,
val fromClass: KClass<*>?
@Transient val fromClass: KClass<*>? = null
// TODO: copy properties from KType
) {
) : Serializable {
/**
* Constructs KotlinType from fully-qualified [qualifiedTypeName] in a dot-separated form, e.g. "org.acme.Outer.Inner"
*/
@@ -7,6 +7,7 @@
package kotlin.script.experimental.api
import java.io.Serializable
import kotlin.reflect.KClass
import kotlin.script.experimental.util.PropertiesCollection
@@ -104,17 +105,17 @@ typealias RefineScriptCompilationConfigurationHandler =
// to make it "hasheable" for cashing
class RefineConfigurationBeforeParsingData(
val handler: RefineScriptCompilationConfigurationHandler
)
) : Serializable
class RefineConfigurationOnAnnotationsData(
val annotations: List<KotlinType>,
val handler: RefineScriptCompilationConfigurationHandler
)
) : Serializable
class RefineConfigurationOnSectionsData(
val sections: List<String>,
val handler: RefineScriptCompilationConfigurationHandler
)
) : Serializable
interface ScriptCompiler {
@@ -7,6 +7,7 @@
package kotlin.script.experimental.api
import java.io.Serializable
import java.net.URL
import kotlin.script.experimental.util.PropertiesCollection
@@ -39,7 +40,7 @@ data class ResolvingRestrictionRule(
}
}
interface ScriptDependency {
interface ScriptDependency : Serializable {
// Q: anything generic here?
}
@@ -5,14 +5,25 @@
package kotlin.script.experimental.util
import java.io.Serializable
import kotlin.reflect.KClass
import kotlin.reflect.KProperty
import kotlin.reflect.KType
import kotlin.script.experimental.api.KotlinType
open class PropertiesCollection(private val properties: Map<Key<*>, Any> = emptyMap()) {
open class PropertiesCollection(private val properties: Map<Key<*>, Any> = emptyMap()) : Serializable {
data class Key<T>(val name: String, val defaultValue: T? = null)
class Key<T>(val name: String, @Transient val defaultValue: T? = null) : Serializable {
override fun equals(other: Any?): Boolean = if (other is Key<*>) name == other.name else false
override fun hashCode(): Int = name.hashCode()
override fun toString(): String = "Key($name)"
companion object {
@JvmStatic
private val serialVersionUID = 0L
}
}
class PropertyKeyDelegate<T>(private val defaultValue: T? = null) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Key<T> =
@@ -36,6 +47,9 @@ open class PropertiesCollection(private val properties: Map<Key<*>, Any> = empty
companion object {
fun <T> key(defaultValue: T? = null) = PropertyKeyDelegate(defaultValue)
fun <T> keyCopy(source: Key<T>) = PropertyKeyCopyDelegate(source)
@JvmStatic
private val serialVersionUID = 0L
}
// properties builder base class (DSL for building properties collection)