From a5a78b8f91f8a51c2ce1c36aa2f0239a7089014c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 15 Jun 2017 20:01:17 +0300 Subject: [PATCH] Minor refactoring in ClasspathRootsResolver.convertClasspathRoots Package prefix only makes sense for JavaSourceRoot content roots --- .../jvm/compiler/ClasspathRootsResolver.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt index 8c26013a05f..7f9b1c12ec2 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt @@ -40,27 +40,27 @@ internal class ClasspathRootsResolver( private val javaModuleFinder = CliJavaModuleFinder(VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JRT_PROTOCOL)) private val javaModuleGraph = JavaModuleGraph(javaModuleFinder) - fun convertClasspathRoots(roots: Iterable): List { + fun convertClasspathRoots(contentRoots: Iterable): List { val result = mutableListOf() - for (javaRoot in roots) { - if (javaRoot !is JvmContentRoot) continue - val virtualFile = contentRootToVirtualFile(javaRoot) ?: continue + for (contentRoot in contentRoots) { + if (contentRoot !is JvmContentRoot) continue + val root = contentRootToVirtualFile(contentRoot) ?: continue - val prefixPackageFqName = (javaRoot as? JavaSourceRoot)?.packagePrefix?.let { prefix -> - if (isValidJavaFqName(prefix)) FqName(prefix) - else null.also { - report(STRONG_WARNING, "Invalid package prefix name is ignored: $prefix") + when (contentRoot) { + is JavaSourceRoot -> { + result += JavaRoot(root, JavaRoot.RootType.SOURCE, contentRoot.packagePrefix?.let { prefix -> + if (isValidJavaFqName(prefix)) FqName(prefix) + else null.also { + report(STRONG_WARNING, "Invalid package prefix name is ignored: $prefix") + } + }) } + is JvmClasspathRoot -> { + result += JavaRoot(root, JavaRoot.RootType.BINARY) + } + else -> error("Unknown root type: $contentRoot") } - - val rootType = when (javaRoot) { - is JavaSourceRoot -> JavaRoot.RootType.SOURCE - is JvmClasspathRoot -> JavaRoot.RootType.BINARY - else -> error("Unknown root type: $javaRoot") - } - - result.add(JavaRoot(virtualFile, rootType, prefixPackageFqName)) } addModularRoots(result)