Introduce KotlinMetadataFinder#hasMetadataPackage

Before creating a MetadataPackageFragment, check that the corresponding
directory (across the classpath) contains at least one .kotlin_metadata file.
Otherwise we're creating packages for every simple name queried during the
resolution and sometimes prefer a (empty) package to the existing class, for
example when the latter class is star-imported
This commit is contained in:
Alexander Udalov
2016-11-23 16:31:39 +03:00
parent bfb7b21472
commit 0dc31af73d
6 changed files with 28 additions and 1 deletions
@@ -42,6 +42,15 @@ class JvmCliVirtualFileFinder(
return findBinaryClass(classId, classId.shortClassName.asString() + MetadataPackageFragment.METADATA_FILE_EXTENSION)?.inputStream
}
override fun hasMetadataPackage(fqName: FqName): Boolean {
var found = false
index.traverseDirectoriesInPackage(fqName, continueSearch = { dir, _ ->
found = found or dir.children.any { it.extension == MetadataPackageFragment.METADATA_FILE_EXTENSION.substring(1) }
!found
})
return found
}
override fun findBuiltInsData(packageFqName: FqName): InputStream? {
// "<builtins-metadata>" is just a made-up name
// JvmDependenciesIndex requires the ClassId of the class which we're searching for, to cache the last request+result