diff --git a/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt index ca3a098ea59..d7f20bbaacd 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate import org.jetbrains.kotlin.test.ConfigurationKind import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestJdkKind -import org.jetbrains.kotlin.util.KotlinFrontEndException import org.junit.Test import java.io.Closeable import java.io.File @@ -98,7 +97,7 @@ class GenericReplTest : TestCase() { val state = repl.createState() val codeLine0 = ReplCodeLine(0, 0, "val l1 = 1\r\nl1\r\n") - val res0 = repl.replCompiler?.check(state, codeLine0) + val res0 = repl.replCompiler.check(state, codeLine0) val res0c = res0 as? ReplCheckResult.Ok TestCase.assertNotNull("Unexpected compile result: $res0", res0c) } diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt b/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt index 12c5d089b67..899734fa6c5 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt @@ -55,26 +55,12 @@ private fun URL.toFile() = fun classpathFromClassloader(classLoader: ClassLoader): List? = generateSequence(classLoader) { it.parent }.toList().flatMap { (it as? URLClassLoader)?.urLs?.mapNotNull(URL::toFile) ?: emptyList() } -private fun File.existsOrNull(): File? = existsAndCheckOrNull { true } -private inline fun File.existsAndCheckOrNull(check: (File.() -> Boolean)): File? = if (exists() && check()) this else null - private val kotlinCompilerJar: File by lazy { // highest prio - explicit property - System.getProperty("kotlin.compiler.jar")?.let(::File)?.existsOrNull() + System.getProperty("kotlin.compiler.jar")?.let(::File)?.takeIf(File::exists) ?: PathUtil.getKotlinPathsForIdeaPlugin().compilerPath ?: throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.jar property to proper location") } -private fun Iterable.anyOrNull(predicate: (T) -> Boolean) = if (any(predicate)) this else null - -private fun File.matchMaybeVersionedFile(baseName: String) = - name == baseName || - name == baseName.removeSuffix(".jar") || // for classes dirs - name.startsWith(baseName.removeSuffix(".jar") + "-") - -private fun contextClasspath(keyName: String, classLoader: ClassLoader): List? = - ( classpathFromClassloader(classLoader)?.anyOrNull { it.matchMaybeVersionedFile(keyName) } - )?.toList() - private fun scriptCompilationClasspathFromContext(classLoader: ClassLoader): List = ( System.getProperty("kotlin.script.classpath")?.split(File.pathSeparator)?.map(::File) @@ -84,17 +70,17 @@ private fun scriptCompilationClasspathFromContext(classLoader: ClassLoader): Lis } .map { it?.canonicalFile } .distinct() - .mapNotNull { it?.existsOrNull() } + .mapNotNull { it?.takeIf(File::exists) } private val kotlinStdlibJar: File? by lazy { - System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.existsOrNull() - ?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_STDLIB_JAR) }.existsOrNull() + System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.takeIf(File::exists) + ?: File(kotlinCompilerJar.parentFile, KOTLIN_JAVA_STDLIB_JAR).takeIf(File::exists) } private val kotlinScriptRuntimeJar: File? by lazy { - System.getProperty("kotlin.script.runtime.jar")?.let(::File)?.existsOrNull() - ?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_SCRIPT_RUNTIME_JAR) }.existsOrNull() + System.getProperty("kotlin.script.runtime.jar")?.let(::File)?.takeIf(File::exists) + ?: File(kotlinCompilerJar.parentFile, KOTLIN_JAVA_SCRIPT_RUNTIME_JAR).takeIf(File::exists) } private val kotlinScriptStandardJars by lazy { listOf(kotlinStdlibJar, kotlinScriptRuntimeJar) } \ No newline at end of file