Skip to content

Commit f73b8e8

Browse files
committed
Fixes after review
1 parent df64736 commit f73b8e8

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/JvmDependenciesIndex.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ interface JvmDependenciesIndex {
5858
): Set<String>
5959
}
6060

61+
interface JvmDependenciesIndexFactory {
62+
fun makeIndexFor(roots: List<JavaRoot>): JvmDependenciesIndex
63+
}
64+
65+
class JvmStaticDependenciesIndexFactory : JvmDependenciesIndexFactory {
66+
override fun makeIndexFor(roots: List<JavaRoot>): JvmDependenciesIndex = JvmDependenciesIndexImpl(roots)
67+
}
68+
69+
class JvmUpdatableDependenciesIndexFactory : JvmDependenciesIndexFactory {
70+
override fun makeIndexFor(roots: List<JavaRoot>): JvmDependenciesIndex = JvmDependenciesDynamicCompoundIndex().apply {
71+
addIndex(JvmDependenciesIndexImpl(roots))
72+
}
73+
}
74+
6175
// speeds up finding files/classes in classpath/java source roots
6276
// NOT THREADSAFE, needs to be adapted/removed if we want compiler to be multithreaded
6377
// 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 {
355369
}
356370

357371
override fun collectKnownClassNamesInPackage(packageFqName: FqName): Set<String> = lock.read {
358-
indices.fold(hashSetOf(), { s, index -> s.addAll(index.collectKnownClassNamesInPackage(packageFqName)); s })
372+
indices.flatMapTo(hashSetOf()) { it.collectKnownClassNamesInPackage(packageFqName) }
359373
}
360374
}
361375

362376
private fun IntArrayList.lastOrNull() = if (isEmpty) null else get(size() - 1)
363-
private val IntArrayList.indices: IntRange get() = 0..(size() - 1)
377+
private val IntArrayList.indices: IntRange get() = 0..(size() - 1)
378+

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ class KotlinCoreEnvironment private constructor(
154154
}
155155

156156
val initialRoots = configuration.getList(JVMConfigurationKeys.CONTENT_ROOTS).classpathRoots()
157-
val initialIndex = JvmDependenciesIndexImpl(initialRoots)
158-
updateClasspathFromRootsIndex(initialIndex)
159-
160-
// replacing index with updatable one only for REPL mode, so we can add roots to classpath then compiling
161-
// subsequent lines in REPL
162-
rootsIndex = if (!configuration.getBoolean(CommonConfigurationKeys.REPL_MODE)) initialIndex
163-
else JvmDependenciesDynamicCompoundIndex().apply {
164-
addIndex(initialIndex)
165-
}
157+
158+
// TODO: pass index factory in the configuration to avoid selection logic here
159+
// for a moment using updatable index for REPL mode, so we can add roots to classpath then compiling subsequent lines in REPL
160+
val indexFactory = if (configuration.getBoolean(CommonConfigurationKeys.REPL_MODE)) JvmUpdatableDependenciesIndexFactory()
161+
else JvmStaticDependenciesIndexFactory()
162+
163+
rootsIndex = indexFactory.makeIndexFor(initialRoots)
164+
updateClasspathFromRootsIndex(rootsIndex)
165+
166166
(ServiceManager.getService(project, CoreJavaFileManager::class.java)
167167
as KotlinCliJavaFileManagerImpl).initIndex(rootsIndex)
168168

compiler/frontend/src/org/jetbrains/kotlin/script/scriptAnnotationsPreprocessing.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ internal class KtAnnotationWrapper(val psi: KtAnnotationEntry, val targetClass:
4848
// TODO: consider inspecting `trace` to find diagnostics reported during the computation (such as division by zero, integer overflow, invalid annotation parameters etc.)
4949
val argName = arg.getArgumentName()?.asName?.toString()
5050
// TODO: consider reusing arguments mapping logic from compiler code
51+
// TODO: find out how to properly report problems from here (now using bogus arg names as an indicator)
5152
val paramName = when {
5253
argName == null && !namedStarted && targetAnnParams == null -> "$" // TODO: using invalid name here. Drop when annotation constructors will be accessible (se above)
53-
argName == null && !namedStarted -> targetAnnParams?.get(i)?.name ?: throw IllegalArgumentException("Unnamed argument for $name at $i")
54-
argName == null && namedStarted -> throw IllegalArgumentException("Invalid argument sequence for $name at arg $i")
55-
targetAnnParams != null && targetAnnParams.none { it.name == argName } ->
56-
throw IllegalArgumentException("Unknown argument $argName for $name")
54+
argName == null && !namedStarted -> targetAnnParams?.get(i)?.name ?: "$(Unnamed argument for $name at $i)"
55+
argName == null && namedStarted -> "$(Invalid argument sequence for $name at arg $i)"
56+
targetAnnParams != null && targetAnnParams.none { it.name == argName } -> "$(Unknown argument $argName for $name)"
5757
else -> {
5858
namedStarted = true
5959
argName!!
@@ -64,7 +64,7 @@ internal class KtAnnotationWrapper(val psi: KtAnnotationEntry, val targetClass:
6464
res
6565
}
6666

67-
internal class AnnProxyInvocationHandler<out K: KClass<out Any>>(val targetAnnClass: K, val annParams: Map<String, Any?>) : InvocationHandler {
67+
internal class AnnProxyInvocationHandler(val targetAnnClass: KClass<out Annotation>, val annParams: Map<String, Any?>) : InvocationHandler {
6868
override fun invoke(proxy: Any?, method: Method?, params: Array<out Any>?): Any? = method?.let {
6969
// TODO: the functionality with checking annParams size is here only to workaround missing access to constructors in annotations. Drop as soon as possible (see above)
7070
annParams[it.name] ?: if (annParams.size == 1) annParams.values.firstOrNull() else null

0 commit comments

Comments
 (0)