KT-57207 Implement JavaClassFinder.findClasses
- This change is a prerequisite for allowing combined Java symbol providers (in LL FIR) to correctly disambiguate classpath order after getting classes with a combined scope, as the index access of the combined Java symbol provider is not guaranteed to return the class that should be first based on the original dependency order. To be able to disambiguate, a combined Java symbol provider needs access to all class candidates the index can find.
This commit is contained in:
committed by
Space Team
parent
f2e3c593a1
commit
567abd2a1c
@@ -21,6 +21,18 @@ interface JavaClassFinder {
|
||||
fun findClass(request: Request): JavaClass?
|
||||
fun findClass(classId: ClassId): JavaClass? = findClass(Request(classId))
|
||||
|
||||
/**
|
||||
* Finds all classes with the specified [ClassId]. This function should be used if the search space permits such ambiguities and if
|
||||
* [findClass] is not guaranteed to disambiguate by itself. For example, in an IDE context, a broad search scope might lead to multiple
|
||||
* valid candidates, which need to be disambiguated according to classpath order.
|
||||
*
|
||||
* [findClasses] may return a single [JavaClass], even if more could be found, if the resulting [JavaClass] is guaranteed to be the
|
||||
* first in the dependency order.
|
||||
*/
|
||||
fun findClasses(request: Request): List<JavaClass>
|
||||
|
||||
fun findClasses(classId: ClassId): List<JavaClass> = findClasses(Request(classId))
|
||||
|
||||
fun findPackage(fqName: FqName, mayHaveAnnotations: Boolean = true): JavaPackage?
|
||||
|
||||
fun knownClassNamesInPackage(packageFqName: FqName): Set<String>?
|
||||
|
||||
+3
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.runtime.structure.ReflectJavaClass
|
||||
import org.jetbrains.kotlin.descriptors.runtime.structure.ReflectJavaPackage
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFinder {
|
||||
override fun findClass(request: JavaClassFinder.Request): JavaClass? {
|
||||
@@ -36,6 +37,8 @@ class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFi
|
||||
return if (klass != null) ReflectJavaClass(klass) else null
|
||||
}
|
||||
|
||||
override fun findClasses(request: JavaClassFinder.Request): List<JavaClass> = listOfNotNull(findClass(request))
|
||||
|
||||
override fun findPackage(fqName: FqName, mayHaveAnnotations: Boolean): JavaPackage? {
|
||||
// We don't know which packages our class loader has and has not, so we behave as if it contains any package in the world
|
||||
return ReflectJavaPackage(fqName)
|
||||
|
||||
Reference in New Issue
Block a user