Dropping package facades:
- do not depend on package facade in LazyJavaPackageFragment
This commit is contained in:
+13
-1
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.load.java.structure.JavaClass
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
|
|
||||||
class LazyJavaPackageFragment(
|
class LazyJavaPackageFragment(
|
||||||
@@ -40,6 +42,14 @@ class LazyJavaPackageFragment(
|
|||||||
c.components.kotlinClassFinder.findKotlinClass(PackageClassUtils.getPackageClassId(fqName))
|
c.components.kotlinClassFinder.findKotlinClass(PackageClassUtils.getPackageClassId(fqName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val kotlinBinaryClasses by c.storageManager.createLazyValue {
|
||||||
|
val simpleNames = c.components.packageMapper.findPackageParts(fqName.asString())
|
||||||
|
simpleNames.map {
|
||||||
|
val classId = ClassId(fqName, Name.identifier(it))
|
||||||
|
c.components.kotlinClassFinder.findKotlinClass(classId)
|
||||||
|
}.filterNotNull()
|
||||||
|
}
|
||||||
|
|
||||||
internal fun resolveTopLevelClass(javaClass: JavaClass) = topLevelClasses(javaClass)
|
internal fun resolveTopLevelClass(javaClass: JavaClass) = topLevelClasses(javaClass)
|
||||||
|
|
||||||
override fun getMemberScope() = scope
|
override fun getMemberScope() = scope
|
||||||
@@ -47,6 +57,8 @@ class LazyJavaPackageFragment(
|
|||||||
override fun toString() = "lazy java package fragment: $fqName"
|
override fun toString() = "lazy java package fragment: $fqName"
|
||||||
|
|
||||||
override fun getSource(): SourceElement {
|
override fun getSource(): SourceElement {
|
||||||
return KotlinJvmBinarySourceElement(oldPackageFacade ?: return SourceElement.NO_SOURCE)
|
// TODO source element for a bunch of Kotlin binary classes containing members of the same package
|
||||||
|
val representativeClass = kotlinBinaryClasses.firstOrNull() ?: return SourceElement.NO_SOURCE
|
||||||
|
return KotlinJvmBinarySourceElement(representativeClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-15
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.load.java.lazy.resolveKotlinBinaryClass
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||||
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
|
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -41,21 +41,11 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
public class LazyJavaPackageScope(
|
public class LazyJavaPackageScope(
|
||||||
c: LazyJavaResolverContext,
|
c: LazyJavaResolverContext,
|
||||||
private val jPackage: JavaPackage,
|
private val jPackage: JavaPackage,
|
||||||
containingDeclaration: LazyJavaPackageFragment
|
private val containingDeclaration: LazyJavaPackageFragment
|
||||||
) : LazyJavaStaticScope(c, containingDeclaration) {
|
) : LazyJavaStaticScope(c, containingDeclaration) {
|
||||||
private val kotlinBinaryClasses = c.storageManager.createLazyValue {
|
|
||||||
val simpleNames = c.components.packageMapper.findPackageParts(jPackage.getFqName().asString())
|
|
||||||
val packageClassId = PackageClassUtils.getPackageClassId(packageFragment.fqName).packageFqName
|
|
||||||
|
|
||||||
simpleNames.map {
|
|
||||||
val classId = ClassId(packageClassId, Name.identifier(it))
|
|
||||||
c.components.kotlinClassFinder.findKotlinClass(classId)
|
|
||||||
}.filterNotNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val partToFacade = c.storageManager.createLazyValue {
|
private val partToFacade = c.storageManager.createLazyValue {
|
||||||
val result = hashMapOf<String, String>()
|
val result = hashMapOf<String, String>()
|
||||||
kotlinClasses@for (kotlinClass in kotlinBinaryClasses()) {
|
kotlinClasses@for (kotlinClass in containingDeclaration.kotlinBinaryClasses) {
|
||||||
val header = kotlinClass.classHeader
|
val header = kotlinClass.classHeader
|
||||||
when (header.kind) {
|
when (header.kind) {
|
||||||
KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -> {
|
KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -> {
|
||||||
@@ -77,7 +67,7 @@ public class LazyJavaPackageScope(
|
|||||||
partToFacade()[partName]
|
partToFacade()[partName]
|
||||||
|
|
||||||
private val deserializedPackageScope = c.storageManager.createLazyValue {
|
private val deserializedPackageScope = c.storageManager.createLazyValue {
|
||||||
if (kotlinBinaryClasses().isEmpty()) {
|
if (containingDeclaration.kotlinBinaryClasses.isEmpty()) {
|
||||||
// If the scope is queried but no package parts are found, there's a possibility that we're trying to load symbols
|
// If the scope is queried but no package parts are found, there's a possibility that we're trying to load symbols
|
||||||
// from an old package with the binary-incompatible facade.
|
// from an old package with the binary-incompatible facade.
|
||||||
// We try to read the old package facade if there is one, to report the "incompatible ABI version" message.
|
// We try to read the old package facade if there is one, to report the "incompatible ABI version" message.
|
||||||
@@ -88,7 +78,7 @@ public class LazyJavaPackageScope(
|
|||||||
JetScope.Empty
|
JetScope.Empty
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClasses())
|
c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, containingDeclaration.kotlinBinaryClasses)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user