From 15914dac86bae9846c570e6ec765019c7b145400 Mon Sep 17 00:00:00 2001 From: Natalia Selezneva Date: Mon, 19 Mar 2018 10:53:35 +0300 Subject: [PATCH] Add ScriptExpectedLocations annotation to script-runtime. It describes where script file can be found. --- ...inScriptDefinitionFromAnnotatedTemplate.kt | 8 ++++++ .../kotlin/script/KotlinScriptDefinition.kt | 4 +++ .../location/scriptLocation_deprecated.kt | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt diff --git a/compiler/frontend.script/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt b/compiler/frontend.script/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt index cad96f02bc5..03e976f6e70 100644 --- a/compiler/frontend.script/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt +++ b/compiler/frontend.script/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt @@ -32,6 +32,8 @@ import kotlin.reflect.full.primaryConstructor import kotlin.script.dependencies.ScriptDependenciesResolver import kotlin.script.experimental.dependencies.AsyncDependenciesResolver import kotlin.script.experimental.dependencies.DependenciesResolver +import kotlin.script.experimental.location.ScriptExpectedLocations +import kotlin.script.experimental.location.ScriptExpectedLocation import kotlin.script.templates.* open class KotlinScriptDefinitionFromAnnotatedTemplate( @@ -132,6 +134,12 @@ open class KotlinScriptDefinitionFromAnnotatedTemplate( } } + override val scriptExpectedLocations: List by lazy { + takeUnlessError { + template.annotations.firstIsInstanceOrNull() + }?.value?.toList() ?: super.scriptExpectedLocations + } + override val name = template.simpleName!! override fun isScript(fileName: String): Boolean = diff --git a/compiler/psi/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt b/compiler/psi/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt index b3f07e25359..1476efa3425 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.parsing.KotlinParserDefinition import org.jetbrains.kotlin.psi.KtScript import kotlin.reflect.KClass import kotlin.script.experimental.dependencies.DependenciesResolver +import kotlin.script.experimental.location.ScriptExpectedLocation import kotlin.script.templates.standard.ScriptTemplateWithArgs open class KotlinScriptDefinition(val template: KClass) : UserDataHolderBase() { @@ -49,6 +50,9 @@ open class KotlinScriptDefinition(val template: KClass) : UserDataHolde @Deprecated("temporary workaround for missing functionality, will be replaced by the new API soon") open val additionalCompilerArguments: Iterable? = null + + open val scriptExpectedLocations: List = + listOf(ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly) } object StandardScriptDefinition : KotlinScriptDefinition(ScriptTemplateWithArgs::class) diff --git a/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt b/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt new file mode 100644 index 00000000000..77d4748ed77 --- /dev/null +++ b/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt @@ -0,0 +1,25 @@ +/* + * 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.location + +/** + * Describes where script files can be found + */ +@Deprecated("Experimental API") +enum class ScriptExpectedLocation { + SourcesOnly, // Under sources roots + TestsOnly, // Under test sources roots + Libraries, // Under libraries classes or sources + Project, // Under project folder, including sources and test sources roots + Everywhere; +} + +@Deprecated("Experimental API") +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class ScriptExpectedLocations( + val value: Array = [ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly] +) \ No newline at end of file