Improve class name generation for scripts and REPL snippets

- allow to override default name/scheme
- implement host/engine specific names for jsr223 to avoid classloading
  clashes (also fix "eval in eval" test)
This commit is contained in:
Ilya Chernikov
2019-09-16 14:13:09 +02:00
parent 6de05bb2c7
commit d3b826c71d
7 changed files with 43 additions and 7 deletions
@@ -8,6 +8,7 @@ package kotlin.script.experimental.api
import java.io.Serializable
import kotlin.script.experimental.util.PropertiesCollection
// Warning: during the transition to the new REPL infrastructure, should be kept in sync with REPL_CODE_LINE_FIRST_NO/REPL_CODE_LINE_FIRST_GEN
const val REPL_SNIPPET_FIRST_NO = 1
const val REPL_SNIPPET_FIRST_GEN = 1
@@ -48,3 +49,17 @@ val ScriptCompilationConfigurationKeys.repl
*/
val ReplScriptCompilationConfigurationKeys.resultFieldPrefix by PropertiesCollection.key<String>("res")
typealias MakeSnippetIdentifier = (ScriptCompilationConfiguration, ReplSnippetId) -> String
/**
* The REPL snippet class identifier generation function
*/
val ReplScriptCompilationConfigurationKeys.makeSnippetIdentifier by PropertiesCollection.key<MakeSnippetIdentifier>(
{ _, snippetId ->
makeDefaultSnippetIdentifier(snippetId)
})
fun makeDefaultSnippetIdentifier(snippetId: ReplSnippetId) =
"Line_${snippetId.no}${if (snippetId.generation > REPL_SNIPPET_FIRST_GEN) "_gen_${snippetId.generation}" else ""}"
@@ -57,6 +57,11 @@ fun ScriptCompilationConfiguration?.with(body: ScriptCompilationConfiguration.Bu
*/
val ScriptCompilationConfigurationKeys.displayName by PropertiesCollection.key<String>()
/**
* The default script class name
*/
val ScriptCompilationConfigurationKeys.defaultIdentifier by PropertiesCollection.key<String>("Script")
/**
* The script filename extension
* Used for the primary script definition selection as well as to assign a kotlin-specific file type to the files with the extension in Intellij IDEA