Allow multiple ClassDescriptorFactory instances in deserialization
This commit is contained in:
+1
-3
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.createBuiltInPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.TEST_PACKAGE_FQNAME
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDescriptorFactory
|
||||
import org.jetbrains.kotlin.serialization.deserialization.PlatformDependentDeclarationFilter
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
@@ -42,8 +41,7 @@ class BuiltInsSerializerTest : TestCaseWithTmpdir() {
|
||||
val module = KotlinTestUtils.createEmptyModule("<module>", DefaultBuiltIns.Instance)
|
||||
|
||||
val packageFragmentProvider = createBuiltInPackageFragmentProvider(
|
||||
LockBasedStorageManager(), module, setOf(TEST_PACKAGE_FQNAME), ClassDescriptorFactory.EMPTY,
|
||||
PlatformDependentDeclarationFilter.All
|
||||
LockBasedStorageManager(), module, setOf(TEST_PACKAGE_FQNAME), emptyList(), PlatformDependentDeclarationFilter.All
|
||||
) {
|
||||
val file = File(tmpdir, it)
|
||||
if (file.exists()) FileInputStream(file) else null
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -112,7 +113,7 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
|
||||
PackageFragmentProvider packageFragmentProvider = createBuiltInPackageFragmentProvider(
|
||||
storageManager, builtInsModule, BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule),
|
||||
Collections.singletonList(new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule)),
|
||||
PlatformDependentDeclarationFilter.All.INSTANCE,
|
||||
AdditionalClassPartsProvider.None.INSTANCE,
|
||||
new Function1<String, InputStream>() {
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class DeserializationComponentsForJava(
|
||||
components = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, configuration, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
LocalClassifierTypeSettings.Default, errorReporter, lookupTracker, JavaFlexibleTypeDeserializer,
|
||||
ClassDescriptorFactory.EMPTY, notFoundClasses,
|
||||
emptyList(), notFoundClasses,
|
||||
additionalClassPartsProvider = jvmBuiltIns?.settings ?: AdditionalClassPartsProvider.None,
|
||||
platformDependentDeclarationFilter = jvmBuiltIns?.settings ?: PlatformDependentDeclarationFilter.NoPlatformDependent
|
||||
)
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
PackageFragmentProvider packageFragmentProvider = BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(
|
||||
storageManager, builtInsModule, BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule),
|
||||
Collections.singletonList(new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule)),
|
||||
getPlatformDependentDeclarationFilter(),
|
||||
getAdditionalClassPartsProvider(),
|
||||
new Function1<String, InputStream>() {
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ fun createBuiltInPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
packageFqNames: Set<FqName>,
|
||||
classDescriptorFactory: ClassDescriptorFactory,
|
||||
classDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
platformDependentDeclarationFilter: PlatformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
|
||||
loadResource: (String) -> InputStream?
|
||||
@@ -52,7 +52,7 @@ fun createBuiltInPackageFragmentProvider(
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeDeserializer.ThrowException,
|
||||
classDescriptorFactory,
|
||||
classDescriptorFactories,
|
||||
notFoundClasses,
|
||||
additionalClassPartsProvider = additionalClassPartsProvider,
|
||||
platformDependentDeclarationFilter = platformDependentDeclarationFilter
|
||||
|
||||
-6
@@ -25,10 +25,4 @@ interface ClassDescriptorFactory {
|
||||
fun shouldCreateClass(packageFqName: FqName, name: Name): Boolean
|
||||
|
||||
fun createClass(classId: ClassId): ClassDescriptor?
|
||||
|
||||
object EMPTY : ClassDescriptorFactory {
|
||||
override fun shouldCreateClass(packageFqName: FqName, name: Name): Boolean = false
|
||||
|
||||
override fun createClass(classId: ClassId): ClassDescriptor? = null
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -32,7 +32,9 @@ class ClassDeserializer(private val components: DeserializationComponents) {
|
||||
|
||||
private fun createClass(key: ClassKey): ClassDescriptor? {
|
||||
val classId = key.classId
|
||||
components.fictitiousClassDescriptorFactory.createClass(classId)?.let { return it }
|
||||
for (factory in components.fictitiousClassDescriptorFactories) {
|
||||
factory.createClass(classId)?.let { return it }
|
||||
}
|
||||
val (classData, sourceElement) = key.classDataWithSource
|
||||
?: components.classDataFinder.findClassData(classId)
|
||||
?: return null
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class DeserializationComponents(
|
||||
val errorReporter: ErrorReporter,
|
||||
val lookupTracker: LookupTracker,
|
||||
val flexibleTypeDeserializer: FlexibleTypeDeserializer,
|
||||
val fictitiousClassDescriptorFactory: ClassDescriptorFactory,
|
||||
val fictitiousClassDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
val notFoundClasses: NotFoundClasses,
|
||||
val additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
|
||||
val platformDependentDeclarationFilter: PlatformDependentDeclarationFilter = PlatformDependentDeclarationFilter.All
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ open class DeserializedPackageMemberScope(
|
||||
= computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
|
||||
|
||||
override fun hasClass(name: Name) =
|
||||
super.hasClass(name) || c.components.fictitiousClassDescriptorFactory.shouldCreateClass(packageFqName, name)
|
||||
super.hasClass(name) || c.components.fictitiousClassDescriptorFactories.any { it.shouldCreateClass(packageFqName, name) }
|
||||
|
||||
override fun createClassId(name: Name) = ClassId(packageFqName, name)
|
||||
|
||||
|
||||
+1
-2
@@ -51,8 +51,7 @@ class KotlinBuiltInDeserializerForDecompiler(
|
||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default, BuiltInsClassDataFinder(proto, nameResolver),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol), packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeDeserializer.ThrowException, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeDeserializer.ThrowException, emptyList(), notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -33,7 +33,10 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.serialization.ClassDataWithSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
|
||||
@@ -64,7 +67,7 @@ class DeserializerForClassfileDecompiler(
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default, classDataFinder, annotationAndConstantLoader,
|
||||
packageFragmentProvider, ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, JavaFlexibleTypeDeserializer, ClassDescriptorFactory.EMPTY, notFoundClasses
|
||||
LookupTracker.DO_NOTHING, JavaFlexibleTypeDeserializer, emptyList(), notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
@@ -84,7 +87,7 @@ class DeserializerForClassfileDecompiler(
|
||||
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(annotationData, strings)
|
||||
val membersScope = DeserializedPackageMemberScope(
|
||||
createDummyPackageFragment(packageFqName), packageProto, nameResolver,
|
||||
JvmPackagePartSource(binaryClassForPackageClass!!), deserializationComponents
|
||||
JvmPackagePartSource(binaryClassForPackageClass), deserializationComponents
|
||||
) { emptyList() }
|
||||
return membersScope.getContributedDescriptors().toList()
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class KotlinJavaScriptDeserializerForDecompiler(
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default, classDataFinder, annotationAndConstantLoader,
|
||||
packageFragmentProvider, ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, DynamicTypeDeserializer, ClassDescriptorFactory.EMPTY, notFoundClasses
|
||||
LookupTracker.DO_NOTHING, DynamicTypeDeserializer, emptyList(), notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ fun createKotlinJavascriptPackageFragmentProvider(
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
DynamicTypeDeserializer,
|
||||
ClassDescriptorFactory.EMPTY,
|
||||
emptyList(),
|
||||
notFoundClasses
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user