Fixes after review

This commit is contained in:
Ilya Chernikov
2016-08-01 14:55:56 +02:00
parent df64736192
commit f73b8e80be
3 changed files with 30 additions and 15 deletions
@@ -58,6 +58,20 @@ interface JvmDependenciesIndex {
): Set<String>
}
interface JvmDependenciesIndexFactory {
fun makeIndexFor(roots: List<JavaRoot>): JvmDependenciesIndex
}
class JvmStaticDependenciesIndexFactory : JvmDependenciesIndexFactory {
override fun makeIndexFor(roots: List<JavaRoot>): JvmDependenciesIndex = JvmDependenciesIndexImpl(roots)
}
class JvmUpdatableDependenciesIndexFactory : JvmDependenciesIndexFactory {
override fun makeIndexFor(roots: List<JavaRoot>): JvmDependenciesIndex = JvmDependenciesDynamicCompoundIndex().apply {
addIndex(JvmDependenciesIndexImpl(roots))
}
}
// speeds up finding files/classes in classpath/java source roots
// NOT THREADSAFE, needs to be adapted/removed if we want compiler to be multithreaded
// the main idea of this class is for each package to store roots which contains it to avoid excessive file system traversal
@@ -355,9 +369,10 @@ class JvmDependenciesDynamicCompoundIndex() : JvmDependenciesIndex {
}
override fun collectKnownClassNamesInPackage(packageFqName: FqName): Set<String> = lock.read {
indices.fold(hashSetOf(), { s, index -> s.addAll(index.collectKnownClassNamesInPackage(packageFqName)); s })
indices.flatMapTo(hashSetOf()) { it.collectKnownClassNamesInPackage(packageFqName) }
}
}
private fun IntArrayList.lastOrNull() = if (isEmpty) null else get(size() - 1)
private val IntArrayList.indices: IntRange get() = 0..(size() - 1)
private val IntArrayList.indices: IntRange get() = 0..(size() - 1)
@@ -154,15 +154,15 @@ class KotlinCoreEnvironment private constructor(
}
val initialRoots = configuration.getList(JVMConfigurationKeys.CONTENT_ROOTS).classpathRoots()
val initialIndex = JvmDependenciesIndexImpl(initialRoots)
updateClasspathFromRootsIndex(initialIndex)
// replacing index with updatable one only for REPL mode, so we can add roots to classpath then compiling
// subsequent lines in REPL
rootsIndex = if (!configuration.getBoolean(CommonConfigurationKeys.REPL_MODE)) initialIndex
else JvmDependenciesDynamicCompoundIndex().apply {
addIndex(initialIndex)
}
// TODO: pass index factory in the configuration to avoid selection logic here
// for a moment using updatable index for REPL mode, so we can add roots to classpath then compiling subsequent lines in REPL
val indexFactory = if (configuration.getBoolean(CommonConfigurationKeys.REPL_MODE)) JvmUpdatableDependenciesIndexFactory()
else JvmStaticDependenciesIndexFactory()
rootsIndex = indexFactory.makeIndexFor(initialRoots)
updateClasspathFromRootsIndex(rootsIndex)
(ServiceManager.getService(project, CoreJavaFileManager::class.java)
as KotlinCliJavaFileManagerImpl).initIndex(rootsIndex)