Refactor scripting properties:

- flatten the structure
- add some parameters
- replace iterables with lists
- renaming all scope objects uniformily
also:
- fix passing and usage of script sources
- renamings and other minor improvements
This commit is contained in:
Ilya Chernikov
2018-03-28 12:59:10 +02:00
parent 2ddcc280a9
commit 5058c66e8c
18 changed files with 123 additions and 130 deletions
@@ -9,8 +9,6 @@ import java.io.File
import java.net.URL
import kotlin.script.experimental.api.*
fun ScriptSourceFragments.isWholeFile(): Boolean = fragments?.isEmpty() ?: true
fun ScriptSource.getScriptText(): String = when {
text != null -> text!!
location != null ->
@@ -20,13 +18,13 @@ fun ScriptSource.getScriptText(): String = when {
fun getMergedScriptText(script: ScriptSource, configuration: ScriptCompileConfiguration): String {
val originalScriptText = script.getScriptText()
val sourceFragments = configuration.getOrNull(ScriptCompileConfigurationParams.scriptSourceFragments)
return if (sourceFragments == null || sourceFragments.isWholeFile()) {
val sourceFragments = configuration.getOrNull(ScriptCompileConfigurationProperties.sourceFragments)
return if (sourceFragments == null || sourceFragments.isEmpty()) {
originalScriptText
} else {
val sb = StringBuilder(originalScriptText.length)
var prevFragment: ScriptSourceNamedFragment? = null
for (fragment in sourceFragments!!.fragments!!) {
for (fragment in sourceFragments) {
val fragmentStartPos = fragment.range.start.absolutePos
val fragmentEndPos = fragment.range.end.absolutePos
if (fragmentStartPos == null || fragmentEndPos == null)