Fix main-kts jsr223 direct bindings processing

Before the jsr context was configured only when a dependency or import
annotation is encountered, so direct properties mapping didn't work
without using any of the annotations. (It was implemented like this
as a workaround due to the problem with handlers composability, that was
fixed some time ago.)
This commit is contained in:
Ilya Chernikov
2019-09-03 16:48:11 +02:00
parent c5f9e0a399
commit 8989bfa235
2 changed files with 16 additions and 5 deletions
@@ -22,5 +22,15 @@ class MainKtsJsr223Test {
val res2 = engine.eval("x + 2")
Assert.assertEquals(5, res2)
}
@Test
fun testWithDirectBindings() {
val engine = ScriptEngineManager().getEngineByExtension("main.kts")!!
engine.put("z", 6)
val res1 = engine.eval("val x = 7")
Assert.assertNull(res1)
val res2 = engine.eval("z * x")
Assert.assertEquals(42, res2)
}
}
@@ -41,6 +41,11 @@ object MainKtsScriptDefinition : ScriptCompilationConfiguration(
}
refineConfiguration {
onAnnotations(DependsOn::class, Repository::class, Import::class, handler = MainKtsConfigurator())
beforeCompiling { context ->
configureProvidedPropertiesFromJsr223Context(
ScriptConfigurationRefinementContext(context.script, context.compilationConfiguration, context.collectedData)
)
}
}
ide {
acceptedLocations(ScriptAcceptedLocation.Everywhere)
@@ -61,11 +66,7 @@ class MainKtsConfigurator : RefineScriptCompilationConfigurationHandler {
private val resolver = FilesAndIvyResolver()
override operator fun invoke(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> =
processAnnotations(context).onSuccess { updatedConfiguration ->
configureProvidedPropertiesFromJsr223Context(
ScriptConfigurationRefinementContext(context.script, updatedConfiguration, context.collectedData)
)
}
processAnnotations(context)
fun processAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
val diagnostics = arrayListOf<ScriptDiagnostic>()