Support for multiparam dependency annotations (with reservations)

Due to missing feature (#KT-13106) it works either with single argument
or with all named arguments.
This commit is contained in:
Ilya Chernikov
2016-07-14 15:21:17 +02:00
parent 5900cad8b3
commit 210a37e08c
4 changed files with 99 additions and 58 deletions
@@ -69,6 +69,13 @@ class ScriptTest2 {
aClass!!.getConstructor(Integer.TYPE).newInstance(4)
}
@Test
fun testScriptWithDependsAnn2() {
val aClass = compileScript("fib_ext_ann2.kts", ScriptWithIntParam::class, null)
Assert.assertNotNull(aClass)
aClass!!.getConstructor(Integer.TYPE).newInstance(4)
}
private fun compileScript(
scriptPath: String,
scriptBase: KClass<out Any>,
@@ -123,7 +130,7 @@ class TestKotlinScriptDependenciesResolver : ScriptDependenciesResolverEx {
private val kotlinPaths by lazy { PathUtil.getKotlinPathsForCompiler() }
@AcceptedAnnotations(DependsOn::class)
@AcceptedAnnotations(DependsOn::class, DependsOnTwo::class)
override fun resolve(script: ScriptContents,
environment: Map<String, Any?>?,
previousDependencies: KotlinScriptExternalDependencies?
@@ -132,13 +139,20 @@ class TestKotlinScriptDependenciesResolver : ScriptDependenciesResolverEx {
val cp = script.annotations.flatMap {
when (it) {
is DependsOn -> listOf(if (it.path == "@{runtime}") kotlinPaths.runtimePath else File(it.path))
is DependsOnTwo -> listOf(it.path1, it.path2).mapNotNull {
when {
it.isBlank() -> null
it == "@{runtime}" -> kotlinPaths.runtimePath
else -> File(it)
}
}
is InvalidScriptResolverAnnotation -> throw Exception("Invalid annotation ${it.name}", it.error)
else -> throw Exception("Unknown annotation ${it.javaClass}")
}
}
return object : KotlinScriptExternalDependencies {
override val classpath: Iterable<File> = classpathFromClassloader() + cp
override val imports: Iterable<String> = listOf("org.jetbrains.kotlin.scripts.DependsOn")
override val imports: Iterable<String> = listOf("org.jetbrains.kotlin.scripts.DependsOn", "org.jetbrains.kotlin.scripts.DependsOnTwo")
}
}
@@ -167,3 +181,7 @@ abstract class ScriptWithBaseClass(num: Int, passthrough: Int) : TestDSLClassWit
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.RUNTIME)
annotation class DependsOn(val path: String)
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.RUNTIME)
annotation class DependsOnTwo(val unused: String = "", val path1: String = "", val path2: String = "")