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:
+10
@@ -22,5 +22,15 @@ class MainKtsJsr223Test {
|
|||||||
val res2 = engine.eval("x + 2")
|
val res2 = engine.eval("x + 2")
|
||||||
Assert.assertEquals(5, res2)
|
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 {
|
refineConfiguration {
|
||||||
onAnnotations(DependsOn::class, Repository::class, Import::class, handler = MainKtsConfigurator())
|
onAnnotations(DependsOn::class, Repository::class, Import::class, handler = MainKtsConfigurator())
|
||||||
|
beforeCompiling { context ->
|
||||||
|
configureProvidedPropertiesFromJsr223Context(
|
||||||
|
ScriptConfigurationRefinementContext(context.script, context.compilationConfiguration, context.collectedData)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ide {
|
ide {
|
||||||
acceptedLocations(ScriptAcceptedLocation.Everywhere)
|
acceptedLocations(ScriptAcceptedLocation.Everywhere)
|
||||||
@@ -61,11 +66,7 @@ class MainKtsConfigurator : RefineScriptCompilationConfigurationHandler {
|
|||||||
private val resolver = FilesAndIvyResolver()
|
private val resolver = FilesAndIvyResolver()
|
||||||
|
|
||||||
override operator fun invoke(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> =
|
override operator fun invoke(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> =
|
||||||
processAnnotations(context).onSuccess { updatedConfiguration ->
|
processAnnotations(context)
|
||||||
configureProvidedPropertiesFromJsr223Context(
|
|
||||||
ScriptConfigurationRefinementContext(context.script, updatedConfiguration, context.collectedData)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun processAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
|
fun processAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
|
||||||
val diagnostics = arrayListOf<ScriptDiagnostic>()
|
val diagnostics = arrayListOf<ScriptDiagnostic>()
|
||||||
|
|||||||
Reference in New Issue
Block a user