PackageFacadeProvider refactoring
This commit is contained in:
+2
-3
@@ -30,8 +30,7 @@ import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
||||
public class LazyJavaPackageFragmentProvider(
|
||||
components: JavaResolverComponents,
|
||||
module: ModuleDescriptor,
|
||||
reflectionTypes: ReflectionTypes,
|
||||
packageMapper: PackageMappingProvider
|
||||
reflectionTypes: ReflectionTypes
|
||||
) : PackageFragmentProvider {
|
||||
|
||||
private val c =
|
||||
@@ -42,7 +41,7 @@ public class LazyJavaPackageFragmentProvider(
|
||||
fqName ->
|
||||
val jPackage = c.components.finder.findPackage(fqName)
|
||||
if (jPackage != null) {
|
||||
LazyJavaPackageFragment(c, jPackage, packageMapper)
|
||||
LazyJavaPackageFragment(c, jPackage)
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.java.lazy
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFacadeProvider
|
||||
import org.jetbrains.kotlin.load.java.JavaClassFinder
|
||||
import org.jetbrains.kotlin.load.java.components.ExternalAnnotationResolver
|
||||
import org.jetbrains.kotlin.load.java.components.ExternalSignatureResolver
|
||||
@@ -45,7 +46,8 @@ class JavaResolverComponents(
|
||||
val javaPropertyInitializerEvaluator: JavaPropertyInitializerEvaluator,
|
||||
val samConversionResolver: SamConversionResolver,
|
||||
val sourceElementFactory: JavaSourceElementFactory,
|
||||
val moduleClassResolver: ModuleClassResolver
|
||||
val moduleClassResolver: ModuleClassResolver,
|
||||
val packageMapper: PackageFacadeProvider
|
||||
)
|
||||
|
||||
open class LazyJavaResolverContext(
|
||||
|
||||
+1
-4
@@ -19,9 +19,7 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||
import org.jetbrains.kotlin.resolve.scopes.DecapitalizedAnnotationScope
|
||||
@@ -29,8 +27,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
|
||||
class LazyJavaPackageFragment(
|
||||
private val c: LazyJavaResolverContext,
|
||||
private val jPackage: JavaPackage,
|
||||
val packageMapper: PackageMappingProvider
|
||||
private val jPackage: JavaPackage
|
||||
) : PackageFragmentDescriptorImpl(c.module, jPackage.getFqName()) {
|
||||
val scope: LazyJavaPackageScope by lazy { LazyJavaPackageScope(c, jPackage, this) }
|
||||
// Just a temporary hack to inject deprecated decapitalized annotation
|
||||
|
||||
+5
-27
@@ -50,41 +50,19 @@ public class LazyJavaPackageScope(
|
||||
|
||||
public val kotlinBinaryClasses: List<KotlinJvmBinaryClass>
|
||||
init {
|
||||
val pakage = jPackage.getFqName().asString().replace('.', '/')
|
||||
val files = containingDeclaration.packageMapper.findPackageMembers(pakage)
|
||||
val files = c.components.packageMapper.findPackageFacades(jPackage.getFqName().asString().replace('.', '/'))
|
||||
val packageClassId = PackageClassUtils.getPackageClassId(packageFragment.fqName).packageFqName
|
||||
val notFound = arrayListOf<String>()
|
||||
val classFiles = files.map {
|
||||
kotlinBinaryClasses = files.map {
|
||||
val classId = ClassId(packageClassId, Name.identifierNoValidate(it.substringAfterLast("/")))
|
||||
val findKotlinClass = c.components.kotlinClassFinder.findKotlinClass(classId)
|
||||
if (findKotlinClass == null) {
|
||||
notFound.add("$classId")
|
||||
}
|
||||
findKotlinClass
|
||||
}
|
||||
kotlinBinaryClasses = classFiles.filterNotNull()
|
||||
if (kotlinBinaryClasses.size() != classFiles.size()) {
|
||||
println("package: $pakage")
|
||||
println("files: " + files.join())
|
||||
println("not found: " + notFound.join())
|
||||
//assert(kotlinBinaryClasses.size() == classFiles.size(), "${kotlinBinaryClasses.size()} != ${classFiles.size()}")
|
||||
}
|
||||
c.components.kotlinClassFinder.findKotlinClass(classId)
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
private val deserializedPackageScope = c.storageManager.createLazyValue {
|
||||
val kotlinBinaryClass = kotlinBinaryClass
|
||||
if (kotlinBinaryClasses.isEmpty())
|
||||
JetScope.Empty
|
||||
else {
|
||||
|
||||
//if(!kotlinBinaryClasses.isEmpty()) {
|
||||
c.components.deserializedDescriptorResolver.createKotlinNewPackageScope(packageFragment, kotlinBinaryClasses)
|
||||
//print("deserializing " + packageFragment.getName())
|
||||
//}
|
||||
|
||||
// val jetScope = c.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
|
||||
// jetScope
|
||||
|
||||
c.components.deserializedDescriptorResolver.createKotlinNewPackageScope(packageFragment, kotlinBinaryClasses)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ public class ModuleMapping(val moduleMapping: String) {
|
||||
}
|
||||
}
|
||||
|
||||
public class PackageFacades(val internalName: String) {
|
||||
public class PackageFacades(val packageInternalName: String) {
|
||||
|
||||
val parts = linkedSetOf<String>()
|
||||
|
||||
fun serialize(out: Writer) {
|
||||
for (i in parts) {
|
||||
out.write("$internalName->$i\n")
|
||||
out.write("$packageInternalName->$i\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PackageFacades(val internalName: String) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.internalName != internalName) {
|
||||
if (other.packageInternalName != packageInternalName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,6 @@ public class PackageFacades(val internalName: String) {
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return internalName.hashCode() / 3 + parts.size() / 3+ (parts.firstOrNull()?.hashCode() ?: 0) /3
|
||||
return packageInternalName.hashCode() / 3 + parts.size() / 3 + (parts.firstOrNull()?.hashCode() ?: 0) / 3
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user