[minor] Renames and rearrangements for clarity

This commit is contained in:
Ilya Chernikov
2018-03-28 14:28:07 +02:00
parent 5058c66e8c
commit 4a4edf3458
22 changed files with 58 additions and 49 deletions
@@ -7,6 +7,8 @@
package kotlin.script.experimental.api
import kotlin.script.experimental.util.typedKey
object ProcessedScriptDataProperties {
val foundAnnotations by typedKey<List<Annotation>>()
@@ -7,6 +7,8 @@
package kotlin.script.experimental.api
import kotlin.script.experimental.util.ChainedPropertyBag
typealias ScriptCompileConfiguration = ChainedPropertyBag
@@ -15,7 +17,7 @@ typealias ProcessedScriptData = ChainedPropertyBag
interface ScriptCompilationConfigurator {
// constructor(environment: ChainedPropertyBag) // the constructor is expected from implementations
// constructor(environment: ScriptingEnvironment) // the constructor is expected from implementations
val defaultConfiguration: ScriptCompileConfiguration
@@ -9,6 +9,7 @@ package kotlin.script.experimental.api
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.script.experimental.util.typedKey
object ScriptCompileConfigurationProperties {
@@ -7,15 +7,25 @@
package kotlin.script.experimental.api
import kotlin.script.experimental.util.ChainedPropertyBag
import kotlin.script.experimental.util.typedKey
typealias ScriptDefinitionPropertiesBag = ChainedPropertyBag
interface ScriptDefinition {
// constructor(environment: ChainedPropertyBag) // the constructor is expected from implementations
// constructor(environment: ScriptingEnvironment) // the constructor is expected from implementations
val properties: ChainedPropertyBag
val properties: ScriptDefinitionPropertiesBag
val compilationConfigurator: ScriptCompilationConfigurator
val evaluator: ScriptEvaluator<*>?
}
object ScriptDefinitionProperties {
val name by typedKey<String>() // Name of the script type, by default "Kotlin script"
val fileExtension by typedKey<String>() // default: "kts"
}
@@ -1,16 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("unused")
package kotlin.script.experimental.api
object ScriptDefinitionProperties {
val name by typedKey<String>() // Name of the script type, by default "Kotlin script"
val fileExtension by typedKey<String>() // default: "kts"
}
@@ -7,6 +7,9 @@
package kotlin.script.experimental.api
import kotlin.script.experimental.util.ChainedPropertyBag
import kotlin.script.experimental.util.typedKey
object ScriptEvaluationEnvironmentParams {
val implicitReceivers by typedKey<List<Any>>()
@@ -24,7 +27,7 @@ data class EvaluationResult(val returnValue: Any?, val environment: ScriptEvalua
// NOTE: name inconsistency: run vs evaluate
interface ScriptEvaluator<in ScriptBase : Any> {
// constructor(environment: ChainedPropertyBag) // the constructor is expected from implementations
// constructor(environment: ScriptingEnvironment) // the constructor is expected from implementations
suspend fun eval(
compiledScript: CompiledScript<ScriptBase>,
@@ -1,37 +0,0 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package kotlin.script.experimental.api
import kotlin.reflect.KProperty
data class TypedKey<T>(val name: String)
class TypedKeyDelegate<T> {
operator fun getValue(thisRef: Any?, property: KProperty<*>): TypedKey<T> = TypedKey(property.name)
}
fun <T> typedKey() = TypedKeyDelegate<T>()
class ChainedPropertyBag(private val parent: ChainedPropertyBag? = null, pairs: Iterable<Pair<TypedKey<*>, Any?>>) {
constructor(parent: ChainedPropertyBag, vararg pairs: Pair<TypedKey<*>, Any?>) : this(parent, pairs.asIterable())
constructor(vararg pairs: Pair<TypedKey<*>, Any?>) : this(null, pairs.asIterable())
private val data = HashMap<TypedKey<*>, Any?>().also { it.putAll(pairs) }
inline operator fun <reified T> get(key: TypedKey<T>): T = getUnchecked(key) as T
fun <T> getUnchecked(key: TypedKey<T>): Any? =
when {
data.containsKey(key) -> data[key]
parent != null -> parent.getUnchecked(key)
else -> throw IllegalArgumentException("Unknown key $key")
}
inline fun <reified T> getOrNull(key: TypedKey<T>): T? = getOrNullUnchecked(key)?.let { it as T }
fun <T> getOrNullUnchecked(key: TypedKey<T>): Any? = data[key] ?: parent?.getOrNullUnchecked(key)
}
@@ -6,6 +6,10 @@
package kotlin.script.experimental.api
import kotlin.reflect.KClass
import kotlin.script.experimental.util.ChainedPropertyBag
import kotlin.script.experimental.util.typedKey
typealias ScriptingEnvironment = ChainedPropertyBag
object ScriptingEnvironmentProperties {