Refactor properties

This commit is contained in:
Ilya Chernikov
2018-07-15 23:16:48 +02:00
parent 904917c194
commit cf2162c445
13 changed files with 74 additions and 98 deletions
@@ -28,6 +28,6 @@ annotation class KotlinScriptFileExtension(
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class KotlinScriptDefaultCompilationConfiguration(
val compilationConfiguration: KClass<out List<*>> // object or class filled in 0-ary constructor
annotation class KotlinScriptPropertiesFromList(
val definitionProperties: KClass<out List<*>> // object or class filled in 0-ary constructor
)
@@ -1,17 +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.
*/
@file:Suppress("unused")
package kotlin.script.experimental.api
import kotlin.script.experimental.util.typedKey
object ProcessedScriptDataProperties {
val foundAnnotations by typedKey<List<Annotation>>()
val foundFragments by typedKey<List<ScriptSourceNamedFragment>>()
}
@@ -8,12 +8,23 @@
package kotlin.script.experimental.api
import kotlin.script.experimental.util.ChainedPropertyBag
import kotlin.script.experimental.util.typedKey
typealias ScriptCompileConfiguration = ChainedPropertyBag
object ScriptCompileConfigurationProperties {
val sourceFragments by typedKey<List<ScriptSourceNamedFragment>>()
}
typealias ProcessedScriptData = ChainedPropertyBag
object ProcessedScriptDataProperties {
val foundAnnotations by typedKey<List<Annotation>>()
val foundFragments by typedKey<List<ScriptSourceNamedFragment>>()
}
interface RefineScriptCompilationConfiguration {
suspend operator fun invoke(
scriptSource: ScriptSource,
@@ -1,46 +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.
*/
@file:Suppress("unused")
package kotlin.script.experimental.api
import kotlin.script.experimental.util.typedKey
object ScriptCompileConfigurationProperties {
val sourceFragments by typedKey<List<ScriptSourceNamedFragment>>()
val baseClass = ScriptDefinitionProperties.baseClass
val scriptBodyTarget by typedKey<ScriptBodyTarget>()
val scriptImplicitReceivers by typedKey<List<KotlinType>>() // in the order from outer to inner scope
val contextVariables by typedKey<Map<String, KotlinType>>() // external variables
val defaultImports by typedKey<List<String>>()
val restrictions by typedKey<List<ResolvingRestrictionRule>>()
val importedScripts by typedKey<List<ScriptSource>>()
val dependencies by typedKey<List<ScriptDependency>>()
val generatedClassAnnotations by typedKey<List<Annotation>>()
val generatedMethodAnnotations by typedKey<List<Annotation>>()
val compilerOptions by typedKey<List<String>>() // Q: CommonCompilerOptions instead?
val refineConfiguration by typedKey<RefineScriptCompilationConfiguration>() // dynamic configurator
val refineBeforeParsing by typedKey<Boolean>() // default: false
val refineConfigurationOnAnnotations by typedKey<List<KotlinType>>()
val refineConfigurationOnSections by typedKey<List<String>>()
}
@@ -19,5 +19,33 @@ object ScriptDefinitionProperties {
val fileExtension by typedKey<String>() // default: "kts"
val baseClass by typedKey<KotlinType>() // script base class
val scriptBodyTarget by typedKey<ScriptBodyTarget>()
val scriptImplicitReceivers by typedKey<List<KotlinType>>() // in the order from outer to inner scope
val contextVariables by typedKey<Map<String, KotlinType>>() // external variables
val defaultImports by typedKey<List<String>>()
val restrictions by typedKey<List<ResolvingRestrictionRule>>()
val importedScripts by typedKey<List<ScriptSource>>()
val dependencies by typedKey<List<ScriptDependency>>()
val generatedClassAnnotations by typedKey<List<Annotation>>()
val generatedMethodAnnotations by typedKey<List<Annotation>>()
val compilerOptions by typedKey<List<String>>() // Q: CommonCompilerOptions instead?
val refineConfiguration by typedKey<RefineScriptCompilationConfiguration>() // dynamic configurator
val refineBeforeParsing by typedKey<Boolean>() // default: false
val refineConfigurationOnAnnotations by typedKey<List<KotlinType>>()
val refineConfigurationOnSections by typedKey<List<String>>()
}
@@ -9,8 +9,8 @@ import kotlin.reflect.KClass
import kotlin.reflect.full.createInstance
import kotlin.reflect.full.findAnnotation
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.annotations.KotlinScriptDefaultCompilationConfiguration
import kotlin.script.experimental.annotations.KotlinScriptFileExtension
import kotlin.script.experimental.annotations.KotlinScriptPropertiesFromList
import kotlin.script.experimental.api.*
import kotlin.script.experimental.util.TypedKey
@@ -43,9 +43,9 @@ fun createScriptDefinitionFromAnnotatedBaseClass(
propertiesData[ScriptDefinitionProperties.fileExtension] = it.extension
}
propertiesData += ScriptDefinitionProperties.name to mainAnnotation.name
baseClass.annotations.filterIsInstance(KotlinScriptDefaultCompilationConfiguration::class.java).forEach { ann ->
baseClass.annotations.filterIsInstance(KotlinScriptPropertiesFromList::class.java).forEach { ann ->
val params = try {
ann.compilationConfiguration.objectInstance ?: ann.compilationConfiguration.createInstance()
ann.definitionProperties.objectInstance ?: ann.definitionProperties.createInstance()
} catch (e: Throwable) {
throw IllegalArgumentException(ILLEGAL_CONFIG_ANN_ARG, e)
}