Refactor and fixes after review

improving script constructor search algorithm - now default params should be supported
remove prefix Customized- from scripts ModuleInfo-related classes
refactoring ideaModuleInfos after review
refactoring ResolveSessionProvider construction for readability
refactoring KotlinScriptConfigurationManager after review
fixing KotlinScriptDefinitionProvider after review
This commit is contained in:
Ilya Chernikov
2016-06-06 13:16:27 +02:00
parent d5b486eb80
commit 656fcc9775
9 changed files with 61 additions and 118 deletions
@@ -317,8 +317,14 @@ object KotlinToJVMBytecodeCompiler {
catch (e: java.lang.NoSuchMethodException) {
for (ctor in scriptClass.kotlin.constructors) {
val (ctorArgs, scriptArgsLeft) = ctor.parameters.fold(Pair(emptyList<Any>(), scriptArgs), ::foldingFunc)
if (ctorArgs.size == ctor.parameters.size && (scriptArgsLeft == null || scriptArgsLeft.isEmpty()))
return ctor.call(*ctorArgs.toTypedArray())
if (ctorArgs.size <= ctor.parameters.size && (scriptArgsLeft == null || scriptArgsLeft.isEmpty())) {
val argsMap = ctorArgs.zip(ctor.parameters) { a, p -> Pair(p, a) }.toMap()
try {
return ctor.callBy(argsMap)
}
catch (e: Exception) { // TODO: find the exact exception type thrown then callBy fails
}
}
}
}
return null
@@ -92,7 +92,7 @@ private fun tryFindKotlinPathsForScriptClasspathEnvVars(project: Project): Kotli
.map { it() }
.firstOrNull { it.runtimePath.exists() }
private fun generateKotlinScriptClasspathEnvVarsFromPaths(project: Project, paths: KotlinPaths?): Map<String, List<String>> =
fun generateKotlinScriptClasspathEnvVarsFromPaths(project: Project, paths: KotlinPaths?): Map<String, List<String>> =
mapOf("kotlin-runtime" to (paths?.run { listOf(runtimePath.canonicalPath) } ?: emptyList()),
"kotlin-reflect" to (paths?.run { listOf(reflectPath.canonicalPath) } ?: emptyList()),
"project-root" to listOf(project.basePath ?: "."),
@@ -65,7 +65,9 @@ class KotlinScriptDefinitionProvider {
}
fun removeScriptDefinition(scriptDefinition: KotlinScriptDefinition) {
definitions.remove(scriptDefinition)
definitionsLock.write {
definitions.remove(scriptDefinition)
}
}
companion object {