[minor] Renames and rearrangements for clarity
This commit is contained in:
+2
@@ -7,6 +7,8 @@
|
||||
|
||||
package kotlin.script.experimental.api
|
||||
|
||||
import kotlin.script.experimental.util.typedKey
|
||||
|
||||
object ProcessedScriptDataProperties {
|
||||
val foundAnnotations by typedKey<List<Annotation>>()
|
||||
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
|
||||
+1
@@ -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"
|
||||
}
|
||||
-16
@@ -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>,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ package kotlin.script.experimental.basic
|
||||
import kotlin.script.experimental.api.*
|
||||
|
||||
|
||||
class PassThroughCompilationConfigurator(val environment: ChainedPropertyBag) : ScriptCompilationConfigurator {
|
||||
class PassThroughCompilationConfigurator(val environment: ScriptingEnvironment) : ScriptCompilationConfigurator {
|
||||
|
||||
override val defaultConfiguration = ScriptCompileConfiguration(environment)
|
||||
|
||||
@@ -23,7 +23,7 @@ class PassThroughCompilationConfigurator(val environment: ChainedPropertyBag) :
|
||||
configuration.asSuccess()
|
||||
}
|
||||
|
||||
class DummyEvaluator<ScriptBase : Any>(val environment: ChainedPropertyBag) : ScriptEvaluator<ScriptBase> {
|
||||
class DummyEvaluator<ScriptBase : Any>(val environment: ScriptingEnvironment) : ScriptEvaluator<ScriptBase> {
|
||||
override suspend fun eval(
|
||||
compiledScript: CompiledScript<ScriptBase>,
|
||||
scriptEvaluationEnvironment: ScriptEvaluationEnvironment
|
||||
|
||||
+4
-3
@@ -15,10 +15,11 @@ import kotlin.script.experimental.annotations.KotlinScriptFileExtension
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.basic.DummyEvaluator
|
||||
import kotlin.script.experimental.basic.PassThroughCompilationConfigurator
|
||||
import kotlin.script.experimental.util.TypedKey
|
||||
|
||||
private const val ERROR_MSG_PREFIX = "Unable to construct script definition: "
|
||||
|
||||
open class ScriptDefinitionFromAnnotatedBaseClass(val environment: ChainedPropertyBag) : ScriptDefinition {
|
||||
open class ScriptDefinitionFromAnnotatedBaseClass(val environment: ScriptingEnvironment) : ScriptDefinition {
|
||||
|
||||
private val baseClass: KClass<*> = environment.getOrNull(ScriptingEnvironmentProperties.baseClass)
|
||||
?: throw IllegalArgumentException("${ERROR_MSG_PREFIX}Expecting baseClass parameter in the scripting environment")
|
||||
@@ -29,13 +30,13 @@ open class ScriptDefinitionFromAnnotatedBaseClass(val environment: ChainedProper
|
||||
private val explicitDefinition: ScriptDefinition? =
|
||||
mainAnnotation.definition.takeIf { it != this::class }?.let { it.instantiateScriptHandler() }
|
||||
|
||||
override val properties = (explicitDefinition?.properties ?: ChainedPropertyBag()).also { properties ->
|
||||
override val properties = (explicitDefinition?.properties ?: ScriptingEnvironment()).also { properties ->
|
||||
val toAdd = arrayListOf<Pair<TypedKey<*>, Any>>()
|
||||
baseClass.findAnnotation<KotlinScriptFileExtension>()?.let { toAdd += ScriptDefinitionProperties.fileExtension to it }
|
||||
if (properties.getOrNull(ScriptDefinitionProperties.name) == null) {
|
||||
toAdd += ScriptDefinitionProperties.name to baseClass.simpleName!!
|
||||
}
|
||||
ChainedPropertyBag(properties, toAdd)
|
||||
ScriptingEnvironment(properties, toAdd)
|
||||
}
|
||||
|
||||
override val compilationConfigurator =
|
||||
+2
-2
@@ -31,11 +31,11 @@ abstract class BasicScriptingHost<ScriptBase : Any>(
|
||||
|
||||
open fun eval(
|
||||
script: ScriptSource,
|
||||
configuration: ScriptCompileConfiguration,
|
||||
compileConfiguration: ScriptCompileConfiguration,
|
||||
environment: ScriptEvaluationEnvironment
|
||||
): ResultWithDiagnostics<EvaluationResult> =
|
||||
runInCoroutineContext {
|
||||
val compiled = compiler.compile(script, configuration, configurator)
|
||||
val compiled = compiler.compile(script, compileConfiguration, configurator)
|
||||
when (compiled) {
|
||||
is ResultWithDiagnostics.Failure -> compiled
|
||||
is ResultWithDiagnostics.Success -> {
|
||||
|
||||
+5
-2
@@ -1,9 +1,11 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package kotlin.script.experimental.api
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.util
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
@@ -16,6 +18,7 @@ class TypedKeyDelegate<T> {
|
||||
fun <T> typedKey() = TypedKeyDelegate<T>()
|
||||
|
||||
class ChainedPropertyBag(private val parent: ChainedPropertyBag? = null, pairs: Iterable<Pair<TypedKey<*>, Any?>>) {
|
||||
constructor(pairs: Iterable<Pair<TypedKey<*>, Any?>>) : this(null, pairs)
|
||||
constructor(parent: ChainedPropertyBag, vararg pairs: Pair<TypedKey<*>, Any?>) : this(parent, pairs.asIterable())
|
||||
constructor(vararg pairs: Pair<TypedKey<*>, Any?>) : this(null, pairs.asIterable())
|
||||
|
||||
Reference in New Issue
Block a user