Fixes after review

This commit is contained in:
Ilya Chernikov
2018-05-28 15:55:33 +02:00
parent 6218b2bcf6
commit 6fdb8746de
13 changed files with 63 additions and 68 deletions
@@ -8,13 +8,27 @@ package kotlin.script.experimental.api
import kotlin.reflect.KClass
import kotlin.reflect.KType
class KotlinType(
/**
* A Kotlin type representation for using in the scripting API
*/
class KotlinType private constructor(
val typeName: String,
val fromClass: KClass<*>? = null
val fromClass: KClass<*>?
// TODO: copy properties from KType
) {
// TODO: implement other approach for non-class types
constructor(type: KType) : this((type.classifier as KClass<*>).qualifiedName!!, type.classifier as KClass<*>)
/**
* Constructs KotlinType from fully-qualified [qualifiedTypeName] in a dot-separated form, e.g. "org.acme.Outer.Inner"
*/
constructor(qualifiedTypeName: String) : this(qualifiedTypeName, null)
/**
* Constructs KotlinType from reflected [kclass]
*/
constructor(kclass: KClass<*>) : this(kclass.qualifiedName!!, kclass)
// TODO: implement other approach for non-class types
/**
* Constructs KotlinType from reflected [ktype]
*/
constructor(type: KType) : this(type.classifier as KClass<*>)
}
@@ -15,7 +15,7 @@ private const val ILLEGAL_CONFIG_ANN_ARG =
open class AnnotationsBasedCompilationConfigurator(val environment: ScriptingEnvironment) : ScriptCompilationConfigurator {
override val defaultConfiguration by lazy {
override val defaultConfiguration by lazy(LazyThreadSafetyMode.PUBLICATION) {
val baseClass = environment.getScriptBaseClass(this)
val cfg = baseClass.annotations.filterIsInstance(KotlinScriptDefaultCompilationConfiguration::class.java).flatMap { ann ->
val params = try {
@@ -19,7 +19,7 @@ private const val ERROR_MSG_PREFIX = "Unable to construct script definition: "
open class ScriptDefinitionFromAnnotatedBaseClass(val environment: ScriptingEnvironment) : ScriptDefinition {
private val getScriptingClass = environment.getOrNull(ScriptingEnvironmentProperties.getScriptingClass)
?: throw IllegalArgumentException("${ERROR_MSG_PREFIX}Expecting 'getClass' parameter in the scripting environment")
?: throw IllegalArgumentException("${ERROR_MSG_PREFIX}Expecting 'getScriptingClass' parameter in the scripting environment")
private val baseClass: KClass<*> = run {
val baseClassType = environment.getOrNull(ScriptingEnvironmentProperties.baseClass)
@@ -33,13 +33,7 @@ open class ChainedPropertyBag private constructor(private val parent: ChainedPro
inline operator fun <reified T> get(key: TypedKey<T>): T = getRaw(key) as T
fun <T> getRaw(key: TypedKey<T>): Any? =
when {
data.containsKey(key) -> data[key]
parent != null -> parent.getRaw(key)
key.defaultValue != null -> key.defaultValue
else -> throw IllegalArgumentException("Unknown key $key")
}
fun <T> getRaw(key: TypedKey<T>): Any? = getOrNullRaw(key) ?: throw IllegalArgumentException("Unknown key $key")
inline fun <reified T> getOrNull(key: TypedKey<T>): T? = getOrNullRaw(key)?.let { it as T }