Minor refactoring in ClasspathRootsResolver.convertClasspathRoots
Package prefix only makes sense for JavaSourceRoot content roots
This commit is contained in:
@@ -40,27 +40,27 @@ internal class ClasspathRootsResolver(
|
|||||||
private val javaModuleFinder = CliJavaModuleFinder(VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JRT_PROTOCOL))
|
private val javaModuleFinder = CliJavaModuleFinder(VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JRT_PROTOCOL))
|
||||||
private val javaModuleGraph = JavaModuleGraph(javaModuleFinder)
|
private val javaModuleGraph = JavaModuleGraph(javaModuleFinder)
|
||||||
|
|
||||||
fun convertClasspathRoots(roots: Iterable<ContentRoot>): List<JavaRoot> {
|
fun convertClasspathRoots(contentRoots: Iterable<ContentRoot>): List<JavaRoot> {
|
||||||
val result = mutableListOf<JavaRoot>()
|
val result = mutableListOf<JavaRoot>()
|
||||||
|
|
||||||
for (javaRoot in roots) {
|
for (contentRoot in contentRoots) {
|
||||||
if (javaRoot !is JvmContentRoot) continue
|
if (contentRoot !is JvmContentRoot) continue
|
||||||
val virtualFile = contentRootToVirtualFile(javaRoot) ?: continue
|
val root = contentRootToVirtualFile(contentRoot) ?: continue
|
||||||
|
|
||||||
val prefixPackageFqName = (javaRoot as? JavaSourceRoot)?.packagePrefix?.let { prefix ->
|
when (contentRoot) {
|
||||||
if (isValidJavaFqName(prefix)) FqName(prefix)
|
is JavaSourceRoot -> {
|
||||||
else null.also {
|
result += JavaRoot(root, JavaRoot.RootType.SOURCE, contentRoot.packagePrefix?.let { prefix ->
|
||||||
report(STRONG_WARNING, "Invalid package prefix name is ignored: $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)
|
addModularRoots(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user