CliLightClassGenerationSupport: correctly find facade files

This fixes a problem where JvmPackageName annotation could force file
    facades to be in the package different to declared kotlin package
This commit is contained in:
Pavel V. Talanov
2018-03-02 18:46:55 +01:00
parent 00ee5e3d16
commit 27d7bb595f
6 changed files with 66 additions and 18 deletions
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve
import com.google.common.collect.Sets
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext.PACKAGE_TO_FILES
import org.jetbrains.kotlin.util.slicedMap.WritableSlice
interface FilePreprocessorExtension {
fun preprocessFile(file: KtFile)
@@ -28,9 +29,14 @@ class FilePreprocessor(
private fun registerFileByPackage(file: KtFile) {
// Register files corresponding to this package
// The trace currently does not support bi-di multimaps that would handle this task nicer
val fqName = file.packageFqName
val files = trace.get(PACKAGE_TO_FILES, fqName) ?: Sets.newIdentityHashSet()
files.add(file)
trace.record(PACKAGE_TO_FILES, fqName, files)
trace.addElementToSlice(PACKAGE_TO_FILES, file.packageFqName, file)
}
}
}
fun <K, T> BindingTrace.addElementToSlice(
slice: WritableSlice<K, MutableCollection<T>>, key: K, element: T
) {
val elements = get(slice, key) ?: Sets.newIdentityHashSet()
elements.add(element)
record(slice, key, elements)
}