Add ScriptExpectedLocations annotation to script-runtime.
It describes where script file can be found.
This commit is contained in:
+8
@@ -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<ScriptExpectedLocation> by lazy {
|
||||
takeUnlessError {
|
||||
template.annotations.firstIsInstanceOrNull<ScriptExpectedLocations>()
|
||||
}?.value?.toList() ?: super.scriptExpectedLocations
|
||||
}
|
||||
|
||||
override val name = template.simpleName!!
|
||||
|
||||
override fun isScript(fileName: String): Boolean =
|
||||
|
||||
@@ -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<out Any>) : UserDataHolderBase() {
|
||||
@@ -49,6 +50,9 @@ open class KotlinScriptDefinition(val template: KClass<out Any>) : UserDataHolde
|
||||
|
||||
@Deprecated("temporary workaround for missing functionality, will be replaced by the new API soon")
|
||||
open val additionalCompilerArguments: Iterable<String>? = null
|
||||
|
||||
open val scriptExpectedLocations: List<ScriptExpectedLocation> =
|
||||
listOf(ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly)
|
||||
}
|
||||
|
||||
object StandardScriptDefinition : KotlinScriptDefinition(ScriptTemplateWithArgs::class)
|
||||
|
||||
+25
@@ -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> = [ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly]
|
||||
)
|
||||
Reference in New Issue
Block a user