Do not produce error classes for not found annotations
This commit is contained in:
+2
-1
@@ -27,9 +27,10 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class AnnotationAndConstantLoaderImpl(
|
||||
module: ModuleDescriptor,
|
||||
private val notFoundClasses: NotFoundClasses,
|
||||
private val protocol: SerializerExtensionProtocol
|
||||
) : AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget> {
|
||||
private val deserializer = AnnotationDeserializer(module)
|
||||
private val deserializer = AnnotationDeserializer(module, notFoundClasses)
|
||||
|
||||
override fun loadClassAnnotations(
|
||||
classProto: ProtoBuf.Class,
|
||||
|
||||
+2
-3
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
|
||||
class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
||||
class AnnotationDeserializer(private val module: ModuleDescriptor, private val notFoundClasses: NotFoundClasses) {
|
||||
private val builtIns: KotlinBuiltIns
|
||||
get() = module.builtIns
|
||||
|
||||
@@ -164,7 +164,6 @@ class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
||||
}
|
||||
|
||||
private fun resolveClass(classId: ClassId): ClassDescriptor {
|
||||
return module.findClassAcrossModuleDependencies(classId)
|
||||
?: ErrorUtils.createErrorClass(classId.asSingleFqName().asString())
|
||||
return module.findNonGenericClassAcrossDependencies(classId, notFoundClasses)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,11 +37,11 @@ class DeserializationComponents(
|
||||
val lookupTracker: LookupTracker,
|
||||
val flexibleTypeCapabilitiesDeserializer: FlexibleTypeCapabilitiesDeserializer,
|
||||
val fictitiousClassDescriptorFactory: ClassDescriptorFactory,
|
||||
val notFoundClasses: NotFoundClasses,
|
||||
val typeCapabilitiesLoader: TypeCapabilitiesLoader = TypeCapabilitiesLoader.NONE,
|
||||
val additionalSupertypes: AdditionalSupertypes = AdditionalSupertypes.None
|
||||
) {
|
||||
val classDeserializer: ClassDeserializer = ClassDeserializer(this)
|
||||
val notFoundClasses: NotFoundClasses = NotFoundClasses(storageManager, moduleDescriptor)
|
||||
|
||||
fun deserializeClass(classId: ClassId): ClassDescriptor? = classDeserializer.deserializeClass(classId)
|
||||
|
||||
|
||||
+12
@@ -31,3 +31,15 @@ fun ModuleDescriptor.findClassAcrossModuleDependencies(classId: ClassId): ClassD
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Returns a mock class descriptor if no existing class is found.
|
||||
// NB: the returned class has no type parameters and thus cannot be given arguments in types
|
||||
fun ModuleDescriptor.findNonGenericClassAcrossDependencies(classId: ClassId, notFoundClasses: NotFoundClasses): ClassDescriptor {
|
||||
val existingClass = findClassAcrossModuleDependencies(classId)
|
||||
if (existingClass != null) return existingClass
|
||||
|
||||
// Take a list of N zeros, where N is the number of class names in the given ClassId
|
||||
val typeParametersCount = generateSequence(classId) { if (it.isNestedClass) it.outerClassId else null }.map { 0 }.toList()
|
||||
|
||||
return notFoundClasses.get(classId, typeParametersCount).declarationDescriptor as ClassDescriptor
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user