Reformat module 'deserialization', fix warnings/inspections
This commit is contained in:
+11
-11
@@ -21,15 +21,15 @@ import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension
|
||||
|
||||
open class SerializerExtensionProtocol(
|
||||
val extensionRegistry: ExtensionRegistryLite,
|
||||
val packageFqName: GeneratedExtension<ProtoBuf.Package, Int>,
|
||||
val constructorAnnotation: GeneratedExtension<ProtoBuf.Constructor, List<ProtoBuf.Annotation>>,
|
||||
val classAnnotation: GeneratedExtension<ProtoBuf.Class, List<ProtoBuf.Annotation>>,
|
||||
val functionAnnotation: GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>>,
|
||||
val propertyAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
|
||||
val enumEntryAnnotation: GeneratedExtension<ProtoBuf.EnumEntry, List<ProtoBuf.Annotation>>,
|
||||
val compileTimeValue: GeneratedExtension<ProtoBuf.Property, ProtoBuf.Annotation.Argument.Value>,
|
||||
val parameterAnnotation: GeneratedExtension<ProtoBuf.ValueParameter, List<ProtoBuf.Annotation>>,
|
||||
val typeAnnotation: GeneratedExtension<ProtoBuf.Type, List<ProtoBuf.Annotation>>,
|
||||
val typeParameterAnnotation: GeneratedExtension<ProtoBuf.TypeParameter, List<ProtoBuf.Annotation>>
|
||||
val extensionRegistry: ExtensionRegistryLite,
|
||||
val packageFqName: GeneratedExtension<ProtoBuf.Package, Int>,
|
||||
val constructorAnnotation: GeneratedExtension<ProtoBuf.Constructor, List<ProtoBuf.Annotation>>,
|
||||
val classAnnotation: GeneratedExtension<ProtoBuf.Class, List<ProtoBuf.Annotation>>,
|
||||
val functionAnnotation: GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>>,
|
||||
val propertyAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
|
||||
val enumEntryAnnotation: GeneratedExtension<ProtoBuf.EnumEntry, List<ProtoBuf.Annotation>>,
|
||||
val compileTimeValue: GeneratedExtension<ProtoBuf.Property, ProtoBuf.Annotation.Argument.Value>,
|
||||
val parameterAnnotation: GeneratedExtension<ProtoBuf.ValueParameter, List<ProtoBuf.Annotation>>,
|
||||
val typeAnnotation: GeneratedExtension<ProtoBuf.Type, List<ProtoBuf.Annotation>>,
|
||||
val typeParameterAnnotation: GeneratedExtension<ProtoBuf.TypeParameter, List<ProtoBuf.Annotation>>
|
||||
)
|
||||
|
||||
+3
-3
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
abstract class AbstractDeserializedPackageFragmentProvider(
|
||||
protected val storageManager: StorageManager,
|
||||
protected val finder: KotlinMetadataFinder,
|
||||
protected val moduleDescriptor: ModuleDescriptor
|
||||
protected val storageManager: StorageManager,
|
||||
protected val finder: KotlinMetadataFinder,
|
||||
protected val moduleDescriptor: ModuleDescriptor
|
||||
) : PackageFragmentProvider {
|
||||
protected lateinit var components: DeserializationComponents
|
||||
|
||||
|
||||
+21
-21
@@ -25,47 +25,47 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
// TODO: simplify this interface
|
||||
interface AnnotationAndConstantLoader<out A : Any, out C : Any, out T : Any> {
|
||||
fun loadClassAnnotations(
|
||||
container: ProtoContainer.Class
|
||||
container: ProtoContainer.Class
|
||||
): List<A>
|
||||
|
||||
fun loadCallableAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<T>
|
||||
|
||||
fun loadEnumEntryAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.EnumEntry
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.EnumEntry
|
||||
): List<A>
|
||||
|
||||
fun loadValueParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
container: ProtoContainer,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
): List<A>
|
||||
|
||||
fun loadExtensionReceiverParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<A>
|
||||
|
||||
fun loadTypeAnnotations(
|
||||
proto: ProtoBuf.Type,
|
||||
nameResolver: NameResolver
|
||||
proto: ProtoBuf.Type,
|
||||
nameResolver: NameResolver
|
||||
): List<A>
|
||||
|
||||
fun loadTypeParameterAnnotations(
|
||||
proto: ProtoBuf.TypeParameter,
|
||||
nameResolver: NameResolver
|
||||
proto: ProtoBuf.TypeParameter,
|
||||
nameResolver: NameResolver
|
||||
): List<A>
|
||||
|
||||
fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): C?
|
||||
}
|
||||
|
||||
+25
-26
@@ -29,9 +29,9 @@ import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class AnnotationAndConstantLoaderImpl(
|
||||
module: ModuleDescriptor,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
private val protocol: SerializerExtensionProtocol
|
||||
module: ModuleDescriptor,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
private val protocol: SerializerExtensionProtocol
|
||||
) : AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget> {
|
||||
private val deserializer = AnnotationDeserializer(module, notFoundClasses)
|
||||
|
||||
@@ -41,9 +41,9 @@ class AnnotationAndConstantLoaderImpl(
|
||||
}
|
||||
|
||||
override fun loadCallableAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<AnnotationWithTarget> {
|
||||
val annotations = when (proto) {
|
||||
is ProtoBuf.Constructor -> proto.getExtension(protocol.constructorAnnotation)
|
||||
@@ -51,32 +51,35 @@ class AnnotationAndConstantLoaderImpl(
|
||||
is ProtoBuf.Property -> proto.getExtension(protocol.propertyAnnotation)
|
||||
else -> error("Unknown message: $proto")
|
||||
}.orEmpty()
|
||||
return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, container.nameResolver), null) }
|
||||
return annotations.map { annotationProto ->
|
||||
AnnotationWithTarget(deserializer.deserializeAnnotation(annotationProto, container.nameResolver), null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadEnumEntryAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.EnumEntry
|
||||
): List<AnnotationDescriptor> {
|
||||
override fun loadEnumEntryAnnotations(container: ProtoContainer, proto: ProtoBuf.EnumEntry): List<AnnotationDescriptor> {
|
||||
val annotations = proto.getExtension(protocol.enumEntryAnnotation).orEmpty()
|
||||
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) }
|
||||
return annotations.map { annotationProto ->
|
||||
deserializer.deserializeAnnotation(annotationProto, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadValueParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
container: ProtoContainer,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
): List<AnnotationDescriptor> {
|
||||
val annotations = proto.getExtension(protocol.parameterAnnotation).orEmpty()
|
||||
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) }
|
||||
return annotations.map { annotationProto ->
|
||||
deserializer.deserializeAnnotation(annotationProto, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadExtensionReceiverParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<AnnotationDescriptor> = emptyList()
|
||||
|
||||
override fun loadTypeAnnotations(proto: ProtoBuf.Type, nameResolver: NameResolver): List<AnnotationDescriptor> {
|
||||
@@ -87,11 +90,7 @@ class AnnotationAndConstantLoaderImpl(
|
||||
return proto.getExtension(protocol.typeParameterAnnotation).orEmpty().map { deserializer.deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
override fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): ConstantValue<*>? {
|
||||
override fun loadPropertyConstant(container: ProtoContainer, proto: ProtoBuf.Property, expectedType: KotlinType): ConstantValue<*>? {
|
||||
val value = proto.getExtensionOrNull(protocol.compileTimeValue) ?: return null
|
||||
return deserializer.resolveValue(expectedType, value, container.nameResolver)
|
||||
}
|
||||
|
||||
+36
-42
@@ -55,19 +55,15 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
|
||||
}
|
||||
|
||||
private fun resolveArgument(
|
||||
proto: Argument,
|
||||
parameterByName: Map<Name, ValueParameterDescriptor>,
|
||||
nameResolver: NameResolver
|
||||
proto: Argument,
|
||||
parameterByName: Map<Name, ValueParameterDescriptor>,
|
||||
nameResolver: NameResolver
|
||||
): Pair<Name, ConstantValue<*>>? {
|
||||
val parameter = parameterByName[nameResolver.getName(proto.nameId)] ?: return null
|
||||
return Pair(nameResolver.getName(proto.nameId), resolveValue(parameter.type, proto.value, nameResolver))
|
||||
}
|
||||
|
||||
fun resolveValue(
|
||||
expectedType: KotlinType,
|
||||
value: Value,
|
||||
nameResolver: NameResolver
|
||||
): ConstantValue<*> {
|
||||
fun resolveValue(expectedType: KotlinType, value: Value, nameResolver: NameResolver): ConstantValue<*> {
|
||||
val isUnsigned = Flags.IS_UNSIGNED.get(value.flags)
|
||||
|
||||
val result: ConstantValue<*> = when (value.type) {
|
||||
@@ -96,25 +92,24 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
|
||||
val arrayElements = value.arrayElementList
|
||||
|
||||
val actualArrayType =
|
||||
if (arrayElements.isNotEmpty()) {
|
||||
val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver)
|
||||
builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(actualElementType) ?:
|
||||
builtIns.getArrayType(Variance.INVARIANT, actualElementType)
|
||||
}
|
||||
else {
|
||||
// In the case of empty array, no element has the element type, so we fall back to the expected type, if any.
|
||||
// This is not very accurate when annotation class has been changed without recompiling clients,
|
||||
// but should not in fact matter because the value is empty anyway
|
||||
if (expectedIsArray) expectedType else builtIns.getArrayType(Variance.INVARIANT, builtIns.anyType)
|
||||
}
|
||||
if (arrayElements.isNotEmpty()) {
|
||||
val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver)
|
||||
builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(actualElementType)
|
||||
?: builtIns.getArrayType(Variance.INVARIANT, actualElementType)
|
||||
} else {
|
||||
// In the case of empty array, no element has the element type, so we fall back to the expected type, if any.
|
||||
// This is not very accurate when annotation class has been changed without recompiling clients,
|
||||
// but should not in fact matter because the value is empty anyway
|
||||
if (expectedIsArray) expectedType else builtIns.getArrayType(Variance.INVARIANT, builtIns.anyType)
|
||||
}
|
||||
|
||||
val expectedElementType = builtIns.getArrayElementType(if (expectedIsArray) expectedType else actualArrayType)
|
||||
|
||||
ConstantValueFactory.createArrayValue(
|
||||
arrayElements.map {
|
||||
resolveValue(expectedElementType, it, nameResolver)
|
||||
},
|
||||
actualArrayType
|
||||
arrayElements.map {
|
||||
resolveValue(expectedElementType, it, nameResolver)
|
||||
},
|
||||
actualArrayType
|
||||
)
|
||||
}
|
||||
else -> error("Unsupported annotation argument type: ${value.type} (expected $expectedType)")
|
||||
@@ -122,8 +117,7 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
|
||||
|
||||
return if (result.getType(module).isSubtypeOf(expectedType)) {
|
||||
result
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// This means that an annotation class has been changed incompatibly without recompiling clients
|
||||
ErrorValue.create("Unexpected argument value")
|
||||
}
|
||||
@@ -142,24 +136,24 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n
|
||||
}
|
||||
|
||||
private fun resolveArrayElementType(value: Value, nameResolver: NameResolver): SimpleType =
|
||||
with(builtIns) {
|
||||
when (value.type) {
|
||||
Type.BYTE -> byteType
|
||||
Type.CHAR -> charType
|
||||
Type.SHORT -> shortType
|
||||
Type.INT -> intType
|
||||
Type.LONG -> longType
|
||||
Type.FLOAT -> floatType
|
||||
Type.DOUBLE -> doubleType
|
||||
Type.BOOLEAN -> booleanType
|
||||
Type.STRING -> stringType
|
||||
Type.CLASS -> error("Arrays of class literals are not supported yet") // TODO: support arrays of class literals
|
||||
Type.ENUM -> resolveClass(nameResolver.getClassId(value.classId)).defaultType
|
||||
Type.ANNOTATION -> resolveClass(nameResolver.getClassId(value.annotation.id)).defaultType
|
||||
Type.ARRAY -> error("Array of arrays is impossible")
|
||||
else -> error("Unknown type: ${value.type}")
|
||||
}
|
||||
with(builtIns) {
|
||||
when (value.type) {
|
||||
Type.BYTE -> byteType
|
||||
Type.CHAR -> charType
|
||||
Type.SHORT -> shortType
|
||||
Type.INT -> intType
|
||||
Type.LONG -> longType
|
||||
Type.FLOAT -> floatType
|
||||
Type.DOUBLE -> doubleType
|
||||
Type.BOOLEAN -> booleanType
|
||||
Type.STRING -> stringType
|
||||
Type.CLASS -> error("Arrays of class literals are not supported yet") // TODO: support arrays of class literals
|
||||
Type.ENUM -> resolveClass(nameResolver.getClassId(value.classId)).defaultType
|
||||
Type.ANNOTATION -> resolveClass(nameResolver.getClassId(value.annotation.id)).defaultType
|
||||
Type.ARRAY -> error("Array of arrays is impossible")
|
||||
else -> error("Unknown type: ${value.type}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveClass(classId: ClassId): ClassDescriptor {
|
||||
return module.findNonGenericClassAcrossDependencies(classId, notFoundClasses)
|
||||
|
||||
+10
-11
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
|
||||
|
||||
class ClassDeserializer(private val components: DeserializationComponents) {
|
||||
private val classes: (ClassKey) -> ClassDescriptor? =
|
||||
components.storageManager.createMemoizedFunctionWithNullableValues { key -> createClass(key) }
|
||||
components.storageManager.createMemoizedFunctionWithNullableValues { key -> createClass(key) }
|
||||
|
||||
// Additional ClassData parameter is needed to avoid calling ClassDataFinder#findClassData()
|
||||
// if it is already computed at the call site
|
||||
@@ -40,8 +40,8 @@ class ClassDeserializer(private val components: DeserializationComponents) {
|
||||
if (classId in BLACK_LIST) return null
|
||||
|
||||
val (nameResolver, classProto, sourceElement) = key.classData
|
||||
?: components.classDataFinder.findClassData(classId)
|
||||
?: return null
|
||||
?: components.classDataFinder.findClassData(classId)
|
||||
?: return null
|
||||
|
||||
val outerClassId = classId.outerClassId
|
||||
val outerContext = if (outerClassId != null) {
|
||||
@@ -51,17 +51,16 @@ class ClassDeserializer(private val components: DeserializationComponents) {
|
||||
if (!outerClass.hasNestedClass(classId.shortClassName)) return null
|
||||
|
||||
outerClass.c
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val fragments = components.packageFragmentProvider.getPackageFragments(classId.packageFqName)
|
||||
val fragment = fragments.firstOrNull { it !is DeserializedPackageFragment || it.hasTopLevelClass(classId.shortClassName) }
|
||||
?: return null
|
||||
?: return null
|
||||
|
||||
components.createContext(
|
||||
fragment, nameResolver,
|
||||
TypeTable(classProto.typeTable),
|
||||
VersionRequirementTable.create(classProto.versionRequirementTable),
|
||||
containerSource = null
|
||||
fragment, nameResolver,
|
||||
TypeTable(classProto.typeTable),
|
||||
VersionRequirementTable.create(classProto.versionRequirementTable),
|
||||
containerSource = null
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,7 +82,7 @@ class ClassDeserializer(private val components: DeserializationComponents) {
|
||||
* but the metadata is still serialized for kotlin-reflect 1.0 to work (see BuiltInsSerializer.kt).
|
||||
*/
|
||||
val BLACK_LIST = setOf(
|
||||
ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.cloneable.toSafe())
|
||||
ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.cloneable.toSafe())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -22,22 +22,22 @@ import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
|
||||
interface ContractDeserializer {
|
||||
fun deserializeContractFromFunction(
|
||||
proto: ProtoBuf.Function,
|
||||
ownerFunction: FunctionDescriptor,
|
||||
typeTable: TypeTable,
|
||||
typeDeserializer: TypeDeserializer
|
||||
proto: ProtoBuf.Function,
|
||||
ownerFunction: FunctionDescriptor,
|
||||
typeTable: TypeTable,
|
||||
typeDeserializer: TypeDeserializer
|
||||
): Pair<FunctionDescriptor.UserDataKey<*>, ContractProvider>?
|
||||
|
||||
companion object {
|
||||
val DEFAULT = object : ContractDeserializer {
|
||||
override fun deserializeContractFromFunction(
|
||||
proto: ProtoBuf.Function,
|
||||
ownerFunction: FunctionDescriptor,
|
||||
typeTable: TypeTable,
|
||||
typeDeserializer: TypeDeserializer
|
||||
proto: ProtoBuf.Function,
|
||||
ownerFunction: FunctionDescriptor,
|
||||
typeTable: TypeTable,
|
||||
typeDeserializer: TypeDeserializer
|
||||
): Pair<FunctionDescriptor.UserDataKey<*>, Nothing>? = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ContractProvider
|
||||
interface ContractProvider
|
||||
|
||||
+3
-3
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
abstract class DeserializedPackageFragment(
|
||||
fqName: FqName,
|
||||
protected val storageManager: StorageManager,
|
||||
module: ModuleDescriptor
|
||||
fqName: FqName,
|
||||
protected val storageManager: StorageManager,
|
||||
module: ModuleDescriptor
|
||||
) : PackageFragmentDescriptorImpl(module, fqName) {
|
||||
|
||||
abstract fun initialize(components: DeserializationComponents)
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ interface FlexibleTypeDeserializer {
|
||||
fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType
|
||||
|
||||
object ThrowException : FlexibleTypeDeserializer {
|
||||
override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType
|
||||
= throw IllegalArgumentException("This method should not be used.")
|
||||
override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType =
|
||||
throw IllegalArgumentException("This method should not be used.")
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
data class IncompatibleVersionErrorData<out T : BinaryVersion>(
|
||||
val actualVersion: T,
|
||||
val expectedVersion: T,
|
||||
val filePath: String,
|
||||
val classId: ClassId
|
||||
val actualVersion: T,
|
||||
val expectedVersion: T,
|
||||
val filePath: String,
|
||||
val classId: ClassId
|
||||
)
|
||||
|
||||
+1
-1
@@ -276,7 +276,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
c.containingDeclaration.asProtoContainer()?.let {
|
||||
c.components.annotationAndConstantLoader
|
||||
.loadExtensionReceiverParameterAnnotations(it, proto, receiverTargetedKind)
|
||||
.map { AnnotationWithTarget(it, AnnotationUseSiteTarget.RECEIVER) }
|
||||
.map { annotation -> AnnotationWithTarget(annotation, AnnotationUseSiteTarget.RECEIVER) }
|
||||
.toList()
|
||||
}.orEmpty()
|
||||
}
|
||||
|
||||
+32
-32
@@ -36,36 +36,36 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
class MetadataPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
finder: KotlinMetadataFinder,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
private val metadataPartProvider: MetadataPartProvider
|
||||
storageManager: StorageManager,
|
||||
finder: KotlinMetadataFinder,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
private val metadataPartProvider: MetadataPartProvider
|
||||
) : AbstractDeserializedPackageFragmentProvider(storageManager, finder, moduleDescriptor) {
|
||||
init {
|
||||
components = DeserializationComponents(
|
||||
storageManager,
|
||||
moduleDescriptor,
|
||||
DeserializationConfiguration.Default, // TODO
|
||||
DeserializedClassDataFinder(this),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol),
|
||||
this,
|
||||
LocalClassifierTypeSettings.Default,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeDeserializer.ThrowException,
|
||||
emptyList(),
|
||||
notFoundClasses,
|
||||
ContractDeserializer.DEFAULT,
|
||||
AdditionalClassPartsProvider.None, PlatformDependentDeclarationFilter.All,
|
||||
BuiltInSerializerProtocol.extensionRegistry
|
||||
storageManager,
|
||||
moduleDescriptor,
|
||||
DeserializationConfiguration.Default, // TODO
|
||||
DeserializedClassDataFinder(this),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol),
|
||||
this,
|
||||
LocalClassifierTypeSettings.Default,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeDeserializer.ThrowException,
|
||||
emptyList(),
|
||||
notFoundClasses,
|
||||
ContractDeserializer.DEFAULT,
|
||||
AdditionalClassPartsProvider.None, PlatformDependentDeclarationFilter.All,
|
||||
BuiltInSerializerProtocol.extensionRegistry
|
||||
)
|
||||
}
|
||||
|
||||
override fun findPackage(fqName: FqName): DeserializedPackageFragment? =
|
||||
if (finder.hasMetadataPackage(fqName))
|
||||
MetadataPackageFragment(fqName, storageManager, moduleDescriptor, metadataPartProvider, finder)
|
||||
else null
|
||||
if (finder.hasMetadataPackage(fqName))
|
||||
MetadataPackageFragment(fqName, storageManager, moduleDescriptor, metadataPartProvider, finder)
|
||||
else null
|
||||
}
|
||||
|
||||
class MetadataPackageFragment(
|
||||
@@ -104,15 +104,15 @@ class MetadataPackageFragment(
|
||||
val (proto, nameResolver) = readProto(stream)
|
||||
|
||||
scopes.add(DeserializedPackageMemberScope(
|
||||
this, proto.`package`, nameResolver, containerSource = null, components = components, classNames = { emptyList() }
|
||||
this, proto.`package`, nameResolver, containerSource = null, components = components, classNames = { emptyList() }
|
||||
))
|
||||
}
|
||||
|
||||
// Also add the deserialized scope that can load all classes from this package
|
||||
scopes.add(object : DeserializedPackageMemberScope(
|
||||
this, ProtoBuf.Package.getDefaultInstance(),
|
||||
NameResolverImpl(ProtoBuf.StringTable.getDefaultInstance(), ProtoBuf.QualifiedNameTable.getDefaultInstance()),
|
||||
containerSource = null, components = components, classNames = { emptyList() }
|
||||
this, ProtoBuf.Package.getDefaultInstance(),
|
||||
NameResolverImpl(ProtoBuf.StringTable.getDefaultInstance(), ProtoBuf.QualifiedNameTable.getDefaultInstance()),
|
||||
containerSource = null, components = components, classNames = { emptyList() }
|
||||
) {
|
||||
override fun hasClass(name: Name): Boolean = hasTopLevelClass(name)
|
||||
override fun definitelyDoesNotContainName(name: Name) = false
|
||||
@@ -135,9 +135,9 @@ class MetadataPackageFragment(
|
||||
if (!version.isCompatible()) {
|
||||
// TODO: report a proper diagnostic
|
||||
throw UnsupportedOperationException(
|
||||
"Kotlin metadata definition format version is not supported: " +
|
||||
"expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " +
|
||||
"Please update Kotlin"
|
||||
"Kotlin metadata definition format version is not supported: " +
|
||||
"expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " +
|
||||
"Please update Kotlin"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ class MetadataPackageFragment(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val DOT_METADATA_FILE_EXTENSION = ".kotlin_metadata"
|
||||
val METADATA_FILE_EXTENSION = "kotlin_metadata"
|
||||
const val METADATA_FILE_EXTENSION = "kotlin_metadata"
|
||||
const val DOT_METADATA_FILE_EXTENSION = ".$METADATA_FILE_EXTENSION"
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -22,14 +22,14 @@ import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
class ProtoBasedClassDataFinder(
|
||||
proto: ProtoBuf.PackageFragment,
|
||||
private val nameResolver: NameResolver,
|
||||
private val classSource: (ClassId) -> SourceElement = { SourceElement.NO_SOURCE }
|
||||
proto: ProtoBuf.PackageFragment,
|
||||
private val nameResolver: NameResolver,
|
||||
private val classSource: (ClassId) -> SourceElement = { SourceElement.NO_SOURCE }
|
||||
) : ClassDataFinder {
|
||||
private val classIdToProto =
|
||||
proto.class_List.associateBy { klass ->
|
||||
nameResolver.getClassId(klass.fqName)
|
||||
}
|
||||
proto.class_List.associateBy { klass ->
|
||||
nameResolver.getClassId(klass.fqName)
|
||||
}
|
||||
|
||||
internal val allClassIds: Collection<ClassId> get() = classIdToProto.keys
|
||||
|
||||
|
||||
+12
-12
@@ -25,16 +25,16 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
sealed class ProtoContainer(
|
||||
val nameResolver: NameResolver,
|
||||
val typeTable: TypeTable,
|
||||
val source: SourceElement?
|
||||
val nameResolver: NameResolver,
|
||||
val typeTable: TypeTable,
|
||||
val source: SourceElement?
|
||||
) {
|
||||
class Class(
|
||||
val classProto: ProtoBuf.Class,
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
source: SourceElement?,
|
||||
val outerClass: ProtoContainer.Class?
|
||||
val classProto: ProtoBuf.Class,
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
source: SourceElement?,
|
||||
val outerClass: ProtoContainer.Class?
|
||||
) : ProtoContainer(nameResolver, typeTable, source) {
|
||||
val classId: ClassId = nameResolver.getClassId(classProto.fqName)
|
||||
|
||||
@@ -45,10 +45,10 @@ sealed class ProtoContainer(
|
||||
}
|
||||
|
||||
class Package(
|
||||
val fqName: FqName,
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
source: SourceElement?
|
||||
val fqName: FqName,
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
source: SourceElement?
|
||||
) : ProtoContainer(nameResolver, typeTable, source) {
|
||||
override fun debugFqName(): FqName = fqName
|
||||
}
|
||||
|
||||
+8
-10
@@ -86,8 +86,8 @@ class TypeDeserializer(
|
||||
fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
|
||||
argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty()
|
||||
|
||||
val arguments = proto.collectAllArguments().mapIndexed { index, proto ->
|
||||
typeArgument(constructor.parameters.getOrNull(index), proto)
|
||||
val arguments = proto.collectAllArguments().mapIndexed { index, argumentProto ->
|
||||
typeArgument(constructor.parameters.getOrNull(index), argumentProto)
|
||||
}.toList()
|
||||
|
||||
val simpleType = if (Flags.SUSPEND_TYPE.get(proto.flags)) {
|
||||
@@ -115,7 +115,7 @@ class TypeDeserializer(
|
||||
proto.hasClassName() -> (classDescriptors(proto.className) ?: notFoundClass(proto.className)).typeConstructor
|
||||
proto.hasTypeParameter() ->
|
||||
typeParameterTypeConstructor(proto.typeParameter)
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unknown type parameter ${proto.typeParameter}")
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unknown type parameter ${proto.typeParameter}")
|
||||
proto.hasTypeParameterName() -> {
|
||||
val container = c.containingDeclaration
|
||||
val name = c.nameResolver.getString(proto.typeParameterName)
|
||||
@@ -171,12 +171,10 @@ class TypeDeserializer(
|
||||
// kotlin.suspend is still built with LV=1.2, thus it references old Continuation
|
||||
// And otherwise, once stdlib is compiled with 1.3 one may want to stay at LV=1.2
|
||||
if (c.containingDeclaration.safeAs<CallableDescriptor>()?.fqNameOrNull() == KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME) {
|
||||
transformRuntimeFunctionTypeToSuspendFunction(functionType, false)?.let {
|
||||
if (!it.isSuspendFunctionType) {
|
||||
transformRuntimeFunctionTypeToSuspendFunction(functionType, true)?.let { return it }
|
||||
} else {
|
||||
return it
|
||||
}
|
||||
transformRuntimeFunctionTypeToSuspendFunction(functionType, false)?.let { oldSuspend ->
|
||||
if (oldSuspend.isSuspendFunctionType) return oldSuspend
|
||||
|
||||
transformRuntimeFunctionTypeToSuspendFunction(functionType, true)?.let { newSuspend -> return newSuspend }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +184,7 @@ class TypeDeserializer(
|
||||
}
|
||||
|
||||
private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? =
|
||||
typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId)
|
||||
typeParameterDescriptors[typeParameterId]?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId)
|
||||
|
||||
private fun computeClassDescriptor(fqNameIndex: Int): ClassDescriptor? {
|
||||
val id = c.nameResolver.getClassId(fqNameIndex)
|
||||
|
||||
+45
-41
@@ -34,63 +34,67 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
class DeserializationComponents(
|
||||
val storageManager: StorageManager,
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val configuration: DeserializationConfiguration,
|
||||
val classDataFinder: ClassDataFinder,
|
||||
val annotationAndConstantLoader: AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget>,
|
||||
val packageFragmentProvider: PackageFragmentProvider,
|
||||
val localClassifierTypeSettings: LocalClassifierTypeSettings,
|
||||
val errorReporter: ErrorReporter,
|
||||
val lookupTracker: LookupTracker,
|
||||
val flexibleTypeDeserializer: FlexibleTypeDeserializer,
|
||||
val fictitiousClassDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
val notFoundClasses: NotFoundClasses,
|
||||
val contractDeserializer: ContractDeserializer,
|
||||
val additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
|
||||
val platformDependentDeclarationFilter: PlatformDependentDeclarationFilter = PlatformDependentDeclarationFilter.All,
|
||||
val extensionRegistryLite: ExtensionRegistryLite
|
||||
val storageManager: StorageManager,
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val configuration: DeserializationConfiguration,
|
||||
val classDataFinder: ClassDataFinder,
|
||||
val annotationAndConstantLoader: AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget>,
|
||||
val packageFragmentProvider: PackageFragmentProvider,
|
||||
val localClassifierTypeSettings: LocalClassifierTypeSettings,
|
||||
val errorReporter: ErrorReporter,
|
||||
val lookupTracker: LookupTracker,
|
||||
val flexibleTypeDeserializer: FlexibleTypeDeserializer,
|
||||
val fictitiousClassDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
val notFoundClasses: NotFoundClasses,
|
||||
val contractDeserializer: ContractDeserializer,
|
||||
val additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
|
||||
val platformDependentDeclarationFilter: PlatformDependentDeclarationFilter = PlatformDependentDeclarationFilter.All,
|
||||
val extensionRegistryLite: ExtensionRegistryLite
|
||||
) {
|
||||
val classDeserializer: ClassDeserializer = ClassDeserializer(this)
|
||||
|
||||
fun deserializeClass(classId: ClassId): ClassDescriptor? = classDeserializer.deserializeClass(classId)
|
||||
|
||||
fun createContext(
|
||||
descriptor: PackageFragmentDescriptor,
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
versionRequirementTable: VersionRequirementTable,
|
||||
containerSource: DeserializedContainerSource?
|
||||
descriptor: PackageFragmentDescriptor,
|
||||
nameResolver: NameResolver,
|
||||
typeTable: TypeTable,
|
||||
versionRequirementTable: VersionRequirementTable,
|
||||
containerSource: DeserializedContainerSource?
|
||||
): DeserializationContext =
|
||||
DeserializationContext(this, nameResolver, descriptor, typeTable, versionRequirementTable, containerSource,
|
||||
parentTypeDeserializer = null, typeParameters = listOf())
|
||||
DeserializationContext(
|
||||
this, nameResolver, descriptor, typeTable, versionRequirementTable, containerSource,
|
||||
parentTypeDeserializer = null, typeParameters = listOf()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class DeserializationContext(
|
||||
val components: DeserializationComponents,
|
||||
val nameResolver: NameResolver,
|
||||
val containingDeclaration: DeclarationDescriptor,
|
||||
val typeTable: TypeTable,
|
||||
val versionRequirementTable: VersionRequirementTable,
|
||||
val containerSource: DeserializedContainerSource?,
|
||||
parentTypeDeserializer: TypeDeserializer?,
|
||||
typeParameters: List<ProtoBuf.TypeParameter>
|
||||
val components: DeserializationComponents,
|
||||
val nameResolver: NameResolver,
|
||||
val containingDeclaration: DeclarationDescriptor,
|
||||
val typeTable: TypeTable,
|
||||
val versionRequirementTable: VersionRequirementTable,
|
||||
val containerSource: DeserializedContainerSource?,
|
||||
parentTypeDeserializer: TypeDeserializer?,
|
||||
typeParameters: List<ProtoBuf.TypeParameter>
|
||||
) {
|
||||
val typeDeserializer = TypeDeserializer(this, parentTypeDeserializer, typeParameters,
|
||||
"Deserializer for ${containingDeclaration.name}")
|
||||
val typeDeserializer: TypeDeserializer = TypeDeserializer(
|
||||
this, parentTypeDeserializer, typeParameters,
|
||||
"Deserializer for ${containingDeclaration.name}"
|
||||
)
|
||||
|
||||
val memberDeserializer = MemberDeserializer(this)
|
||||
val memberDeserializer: MemberDeserializer = MemberDeserializer(this)
|
||||
|
||||
val storageManager: StorageManager get() = components.storageManager
|
||||
|
||||
fun childContext(
|
||||
descriptor: DeclarationDescriptor,
|
||||
typeParameterProtos: List<ProtoBuf.TypeParameter>,
|
||||
nameResolver: NameResolver = this.nameResolver,
|
||||
typeTable: TypeTable = this.typeTable
|
||||
) = DeserializationContext(
|
||||
components, nameResolver, descriptor, typeTable, versionRequirementTable, this.containerSource,
|
||||
parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos
|
||||
descriptor: DeclarationDescriptor,
|
||||
typeParameterProtos: List<ProtoBuf.TypeParameter>,
|
||||
nameResolver: NameResolver = this.nameResolver,
|
||||
typeTable: TypeTable = this.typeTable
|
||||
): DeserializationContext = DeserializationContext(
|
||||
components, nameResolver, descriptor, typeTable, versionRequirementTable, this.containerSource,
|
||||
parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos
|
||||
)
|
||||
}
|
||||
|
||||
+9
-9
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
|
||||
open class DeserializedAnnotations(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationDescriptor>
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationDescriptor>
|
||||
) : Annotations {
|
||||
private val annotations by storageManager.createLazyValue(compute)
|
||||
|
||||
@@ -39,22 +39,22 @@ open class DeserializedAnnotations(
|
||||
}
|
||||
|
||||
class NonEmptyDeserializedAnnotations(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationDescriptor>
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationDescriptor>
|
||||
) : DeserializedAnnotations(storageManager, compute) {
|
||||
override fun isEmpty(): Boolean = false
|
||||
}
|
||||
|
||||
open class DeserializedAnnotationsWithPossibleTargets(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationWithTarget>
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationWithTarget>
|
||||
) : Annotations {
|
||||
private val annotations by storageManager.createLazyValue(compute)
|
||||
|
||||
override fun isEmpty(): Boolean = annotations.isEmpty()
|
||||
|
||||
override fun findAnnotation(fqName: FqName): AnnotationDescriptor? =
|
||||
annotations.firstOrNull { (annotation, target) -> target == null && annotation.fqName == fqName }?.annotation
|
||||
annotations.firstOrNull { (annotation, target) -> target == null && annotation.fqName == fqName }?.annotation
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> = annotations.filter { it.target != null }
|
||||
|
||||
@@ -66,8 +66,8 @@ open class DeserializedAnnotationsWithPossibleTargets(
|
||||
}
|
||||
|
||||
class NonEmptyDeserializedAnnotationsWithPossibleTargets(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationWithTarget>
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationWithTarget>
|
||||
) : DeserializedAnnotationsWithPossibleTargets(storageManager, compute) {
|
||||
override fun isEmpty(): Boolean = false
|
||||
}
|
||||
|
||||
+56
-46
@@ -30,13 +30,13 @@ import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import java.util.*
|
||||
|
||||
class DeserializedClassDescriptor(
|
||||
outerContext: DeserializationContext,
|
||||
val classProto: ProtoBuf.Class,
|
||||
nameResolver: NameResolver,
|
||||
private val sourceElement: SourceElement
|
||||
outerContext: DeserializationContext,
|
||||
val classProto: ProtoBuf.Class,
|
||||
nameResolver: NameResolver,
|
||||
private val sourceElement: SourceElement
|
||||
) : AbstractClassDescriptor(
|
||||
outerContext.storageManager,
|
||||
nameResolver.getClassId(classProto.fqName).shortClassName
|
||||
outerContext.storageManager,
|
||||
nameResolver.getClassId(classProto.fqName).shortClassName
|
||||
) {
|
||||
private val classId = nameResolver.getClassId(classProto.fqName)
|
||||
|
||||
@@ -58,20 +58,19 @@ class DeserializedClassDescriptor(
|
||||
private val sealedSubclasses = c.storageManager.createLazyValue { computeSubclassesForSealedClass() }
|
||||
|
||||
internal val thisAsProtoContainer: ProtoContainer.Class = ProtoContainer.Class(
|
||||
classProto, c.nameResolver, c.typeTable, sourceElement,
|
||||
(containingDeclaration as? DeserializedClassDescriptor)?.thisAsProtoContainer
|
||||
classProto, c.nameResolver, c.typeTable, sourceElement,
|
||||
(containingDeclaration as? DeserializedClassDescriptor)?.thisAsProtoContainer
|
||||
)
|
||||
|
||||
val versionRequirement: VersionRequirement?
|
||||
get() = VersionRequirement.create(classProto, c.nameResolver, c.versionRequirementTable)
|
||||
|
||||
override val annotations =
|
||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
||||
Annotations.EMPTY
|
||||
}
|
||||
else NonEmptyDeserializedAnnotations(c.storageManager) {
|
||||
c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer).toList()
|
||||
}
|
||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
||||
Annotations.EMPTY
|
||||
} else NonEmptyDeserializedAnnotations(c.storageManager) {
|
||||
c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer).toList()
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration
|
||||
|
||||
@@ -116,13 +115,13 @@ class DeserializedClassDescriptor(
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = primaryConstructor()
|
||||
|
||||
private fun computeConstructors(): Collection<ClassConstructorDescriptor> =
|
||||
computeSecondaryConstructors() + listOfNotNull(unsubstitutedPrimaryConstructor) +
|
||||
c.components.additionalClassPartsProvider.getConstructors(this)
|
||||
computeSecondaryConstructors() + listOfNotNull(unsubstitutedPrimaryConstructor) +
|
||||
c.components.additionalClassPartsProvider.getConstructors(this)
|
||||
|
||||
private fun computeSecondaryConstructors(): List<ClassConstructorDescriptor> =
|
||||
classProto.constructorList.filter { Flags.IS_SECONDARY.get(it.flags) }.map {
|
||||
c.memberDeserializer.loadConstructor(it, false)
|
||||
}
|
||||
classProto.constructorList.filter { Flags.IS_SECONDARY.get(it.flags) }.map {
|
||||
c.memberDeserializer.loadConstructor(it, false)
|
||||
}
|
||||
|
||||
override fun getConstructors() = constructors()
|
||||
|
||||
@@ -136,7 +135,7 @@ class DeserializedClassDescriptor(
|
||||
override fun getCompanionObjectDescriptor(): ClassDescriptor? = companionObjectDescriptor()
|
||||
|
||||
internal fun hasNestedClass(name: Name): Boolean =
|
||||
name in memberScope.classNames
|
||||
name in memberScope.classNames
|
||||
|
||||
private fun computeSubclassesForSealedClass(): Collection<ClassDescriptor> {
|
||||
if (modality != Modality.SEALED) return emptyList()
|
||||
@@ -176,8 +175,8 @@ class DeserializedClassDescriptor(
|
||||
|
||||
if (unresolved.isNotEmpty()) {
|
||||
c.components.errorReporter.reportIncompleteHierarchy(
|
||||
this@DeserializedClassDescriptor,
|
||||
unresolved.map { it.classId?.asSingleFqName()?.asString() ?: it.name.asString() }
|
||||
this@DeserializedClassDescriptor,
|
||||
unresolved.map { it.classId?.asSingleFqName()?.asString() ?: it.name.asString() }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -198,8 +197,8 @@ class DeserializedClassDescriptor(
|
||||
}
|
||||
|
||||
private inner class DeserializedClassMemberScope : DeserializedMemberScope(
|
||||
c, classProto.functionList, classProto.propertyList, classProto.typeAliasList,
|
||||
classProto.nestedClassNameList.map(c.nameResolver::getName).let { { it } } // workaround KT-13454
|
||||
c, classProto.functionList, classProto.propertyList, classProto.typeAliasList,
|
||||
classProto.nestedClassNameList.map(c.nameResolver::getName).let { { it } } // workaround KT-13454
|
||||
) {
|
||||
private val classDescriptor: DeserializedClassDescriptor get() = this@DeserializedClassDescriptor
|
||||
|
||||
@@ -208,7 +207,7 @@ class DeserializedClassDescriptor(
|
||||
}
|
||||
|
||||
override fun getContributedDescriptors(
|
||||
kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean
|
||||
kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> = allDescriptors()
|
||||
|
||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
|
||||
@@ -243,20 +242,32 @@ class DeserializedClassDescriptor(
|
||||
generateFakeOverrides(name, fromSupertypes, descriptors)
|
||||
}
|
||||
|
||||
private fun <D : CallableMemberDescriptor> generateFakeOverrides(name: Name, fromSupertypes: Collection<D>, result: MutableCollection<D>) {
|
||||
private fun <D : CallableMemberDescriptor> generateFakeOverrides(
|
||||
name: Name,
|
||||
fromSupertypes: Collection<D>,
|
||||
result: MutableCollection<D>
|
||||
) {
|
||||
val fromCurrent = ArrayList<CallableMemberDescriptor>(result)
|
||||
OverridingUtil.generateOverridesInFunctionGroup(name, fromSupertypes, fromCurrent, classDescriptor, object : NonReportingOverrideStrategy() {
|
||||
override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) {
|
||||
// TODO: report "cannot infer visibility"
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
result.add(fakeOverride as D)
|
||||
}
|
||||
OverridingUtil.generateOverridesInFunctionGroup(
|
||||
name,
|
||||
fromSupertypes,
|
||||
fromCurrent,
|
||||
classDescriptor,
|
||||
object : NonReportingOverrideStrategy() {
|
||||
override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) {
|
||||
// TODO: report "cannot infer visibility"
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
result.add(fakeOverride as D)
|
||||
}
|
||||
|
||||
override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) {
|
||||
// TODO report conflicts
|
||||
}
|
||||
})
|
||||
override fun conflict(
|
||||
fromSuper: CallableMemberDescriptor,
|
||||
fromCurrent: CallableMemberDescriptor
|
||||
) {
|
||||
// TODO report conflicts
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun getNonDeclaredFunctionNames(): Set<Name> {
|
||||
@@ -291,16 +302,15 @@ class DeserializedClassDescriptor(
|
||||
private inner class EnumEntryClassDescriptors {
|
||||
private val enumEntryProtos = classProto.enumEntryList.associateBy { c.nameResolver.getName(it.name) }
|
||||
|
||||
private val enumEntryByName = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> {
|
||||
name ->
|
||||
private val enumEntryByName = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
|
||||
|
||||
enumEntryProtos[name]?.let { proto ->
|
||||
EnumEntrySyntheticClassDescriptor.create(
|
||||
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames,
|
||||
DeserializedAnnotations(c.storageManager) {
|
||||
c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(thisAsProtoContainer, proto).toList()
|
||||
},
|
||||
SourceElement.NO_SOURCE
|
||||
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames,
|
||||
DeserializedAnnotations(c.storageManager) {
|
||||
c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(thisAsProtoContainer, proto).toList()
|
||||
},
|
||||
SourceElement.NO_SOURCE
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -323,10 +333,10 @@ class DeserializedClassDescriptor(
|
||||
}
|
||||
|
||||
return classProto.functionList.mapTo(result) { c.nameResolver.getName(it.name) } +
|
||||
classProto.propertyList.mapTo(result) { c.nameResolver.getName(it.name) }
|
||||
classProto.propertyList.mapTo(result) { c.nameResolver.getName(it.name) }
|
||||
}
|
||||
|
||||
fun all(): Collection<ClassDescriptor> =
|
||||
enumEntryProtos.keys.mapNotNull { name -> findEnumEntry(name) }
|
||||
enumEntryProtos.keys.mapNotNull { name -> findEnumEntry(name) }
|
||||
}
|
||||
}
|
||||
|
||||
+77
-85
@@ -58,33 +58,34 @@ interface DeserializedContainerSource : SourceElement {
|
||||
interface DeserializedCallableMemberDescriptor : DeserializedMemberDescriptor, CallableMemberDescriptor
|
||||
|
||||
class DeserializedSimpleFunctionDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
original: SimpleFunctionDescriptor?,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
override val proto: ProtoBuf.Function,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?,
|
||||
source: SourceElement? = null
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
original: SimpleFunctionDescriptor?,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
override val proto: ProtoBuf.Function,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?,
|
||||
source: SourceElement? = null
|
||||
) : DeserializedCallableMemberDescriptor,
|
||||
SimpleFunctionDescriptorImpl(
|
||||
containingDeclaration, original, annotations, name, kind,
|
||||
source ?: SourceElement.NO_SOURCE) {
|
||||
containingDeclaration, original, annotations, name, kind,
|
||||
source ?: SourceElement.NO_SOURCE
|
||||
) {
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
source: SourceElement
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
source: SourceElement
|
||||
): FunctionDescriptorImpl {
|
||||
return DeserializedSimpleFunctionDescriptor(
|
||||
newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind,
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource, source
|
||||
newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind,
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource, source
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -109,20 +110,20 @@ class DeserializedPropertyDescriptor(
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
) : DeserializedCallableMemberDescriptor, PropertyDescriptorImpl(
|
||||
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE,
|
||||
isLateInit, isConst, isExpect, false, isExternal, isDelegated
|
||||
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE,
|
||||
isLateInit, isConst, isExpect, false, isExternal, isDelegated
|
||||
) {
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
newModality: Modality,
|
||||
newVisibility: Visibility,
|
||||
original: PropertyDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name
|
||||
newOwner: DeclarationDescriptor,
|
||||
newModality: Modality,
|
||||
newVisibility: Visibility,
|
||||
original: PropertyDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name
|
||||
): PropertyDescriptorImpl {
|
||||
return DeserializedPropertyDescriptor(
|
||||
newOwner, original, annotations, newModality, newVisibility, isVar, newName, kind, isLateInit, isConst, isExternal,
|
||||
@Suppress("DEPRECATION") isDelegated, isExpect, proto, nameResolver, typeTable, versionRequirementTable, containerSource
|
||||
newOwner, original, annotations, newModality, newVisibility, isVar, newName, kind, isLateInit, isConst, isExternal,
|
||||
@Suppress("DEPRECATION") isDelegated, isExpect, proto, nameResolver, typeTable, versionRequirementTable, containerSource
|
||||
)
|
||||
}
|
||||
|
||||
@@ -130,31 +131,31 @@ class DeserializedPropertyDescriptor(
|
||||
}
|
||||
|
||||
class DeserializedClassConstructorDescriptor(
|
||||
containingDeclaration: ClassDescriptor,
|
||||
original: ConstructorDescriptor?,
|
||||
annotations: Annotations,
|
||||
isPrimary: Boolean,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
override val proto: ProtoBuf.Constructor,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?,
|
||||
source: SourceElement? = null
|
||||
containingDeclaration: ClassDescriptor,
|
||||
original: ConstructorDescriptor?,
|
||||
annotations: Annotations,
|
||||
isPrimary: Boolean,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
override val proto: ProtoBuf.Constructor,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?,
|
||||
source: SourceElement? = null
|
||||
) : DeserializedCallableMemberDescriptor,
|
||||
ClassConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) {
|
||||
ClassConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) {
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
source: SourceElement
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
source: SourceElement
|
||||
): DeserializedClassConstructorDescriptor {
|
||||
return DeserializedClassConstructorDescriptor(
|
||||
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource, source
|
||||
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource, source
|
||||
)
|
||||
}
|
||||
|
||||
@@ -164,33 +165,33 @@ class DeserializedClassConstructorDescriptor(
|
||||
|
||||
override fun isTailrec(): Boolean = false
|
||||
|
||||
override fun isSuspend(): Boolean = false
|
||||
override fun isSuspend(): Boolean = false
|
||||
}
|
||||
|
||||
class DeserializedTypeAliasDescriptor(
|
||||
override val storageManager: StorageManager,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
override val proto: ProtoBuf.TypeAlias,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
override val storageManager: StorageManager,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
override val proto: ProtoBuf.TypeAlias,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
) : AbstractTypeAliasDescriptor(containingDeclaration, annotations, name, SourceElement.NO_SOURCE, visibility),
|
||||
DeserializedMemberDescriptor {
|
||||
DeserializedMemberDescriptor {
|
||||
override lateinit var constructors: Collection<TypeAliasConstructorDescriptor> private set
|
||||
|
||||
override lateinit var underlyingType: SimpleType private set
|
||||
override lateinit var expandedType: SimpleType private set
|
||||
private lateinit var typeConstructorParameters: List<TypeParameterDescriptor>
|
||||
private lateinit var defaultTypeImpl: SimpleType private set
|
||||
private lateinit var defaultTypeImpl: SimpleType
|
||||
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
underlyingType: SimpleType,
|
||||
expandedType: SimpleType
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
underlyingType: SimpleType,
|
||||
expandedType: SimpleType
|
||||
) {
|
||||
initialize(declaredTypeParameters)
|
||||
this.underlyingType = underlyingType
|
||||
@@ -203,31 +204,22 @@ class DeserializedTypeAliasDescriptor(
|
||||
override val classDescriptor: ClassDescriptor?
|
||||
get() = if (expandedType.isError) null else expandedType.constructor.declarationDescriptor as? ClassDescriptor
|
||||
|
||||
override fun getDefaultType(): SimpleType =
|
||||
defaultTypeImpl
|
||||
override fun getDefaultType(): SimpleType = defaultTypeImpl
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): TypeAliasDescriptor {
|
||||
if (substitutor.isEmpty) return this
|
||||
val substituted = DeserializedTypeAliasDescriptor(
|
||||
storageManager,
|
||||
containingDeclaration,
|
||||
annotations,
|
||||
name,
|
||||
visibility,
|
||||
proto,
|
||||
nameResolver,
|
||||
typeTable,
|
||||
versionRequirementTable,
|
||||
containerSource
|
||||
storageManager, containingDeclaration, annotations, name, visibility,
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource
|
||||
)
|
||||
substituted.initialize(
|
||||
declaredTypeParameters,
|
||||
substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(),
|
||||
substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType()
|
||||
)
|
||||
substituted.initialize(declaredTypeParameters,
|
||||
substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(),
|
||||
substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType())
|
||||
|
||||
return substituted
|
||||
}
|
||||
|
||||
override fun getTypeConstructorTypeParameters(): List<TypeParameterDescriptor> =
|
||||
typeConstructorParameters
|
||||
|
||||
override fun getTypeConstructorTypeParameters(): List<TypeParameterDescriptor> = typeConstructorParameters
|
||||
}
|
||||
|
||||
+33
-33
@@ -38,11 +38,11 @@ import java.io.ByteArrayOutputStream
|
||||
import java.util.*
|
||||
|
||||
abstract class DeserializedMemberScope protected constructor(
|
||||
protected val c: DeserializationContext,
|
||||
functionList: Collection<ProtoBuf.Function>,
|
||||
propertyList: Collection<ProtoBuf.Property>,
|
||||
typeAliasList: Collection<ProtoBuf.TypeAlias>,
|
||||
classNames: () -> Collection<Name>
|
||||
protected val c: DeserializationContext,
|
||||
functionList: Collection<ProtoBuf.Function>,
|
||||
propertyList: Collection<ProtoBuf.Property>,
|
||||
typeAliasList: Collection<ProtoBuf.TypeAlias>,
|
||||
classNames: () -> Collection<Name>
|
||||
) : MemberScopeImpl() {
|
||||
|
||||
private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray()
|
||||
@@ -63,11 +63,11 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
}
|
||||
|
||||
private val functions =
|
||||
c.storageManager.createMemoizedFunction<Name, Collection<SimpleFunctionDescriptor>> { computeFunctions(it) }
|
||||
c.storageManager.createMemoizedFunction<Name, Collection<SimpleFunctionDescriptor>> { computeFunctions(it) }
|
||||
private val properties =
|
||||
c.storageManager.createMemoizedFunction<Name, Collection<PropertyDescriptor>> { computeProperties(it) }
|
||||
c.storageManager.createMemoizedFunction<Name, Collection<PropertyDescriptor>> { computeProperties(it) }
|
||||
private val typeAliasByName =
|
||||
c.storageManager.createMemoizedFunctionWithNullableValues<Name, TypeAliasDescriptor> { createTypeAlias(it) }
|
||||
c.storageManager.createMemoizedFunctionWithNullableValues<Name, TypeAliasDescriptor> { createTypeAlias(it) }
|
||||
|
||||
private val functionNamesLazy by c.storageManager.createLazyValue {
|
||||
functionProtosBytes.keys + getNonDeclaredFunctionNames()
|
||||
@@ -90,7 +90,7 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
}
|
||||
|
||||
private inline fun <M : MessageLite> Collection<M>.groupByName(
|
||||
getNameIndex: (M) -> Int
|
||||
getNameIndex: (M) -> Int
|
||||
) = groupBy { c.nameResolver.getName(getNameIndex(it)) }
|
||||
|
||||
private fun computeFunctions(name: Name) =
|
||||
@@ -166,9 +166,9 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
}
|
||||
|
||||
protected fun computeDescriptors(
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
location: LookupLocation
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
location: LookupLocation
|
||||
): Collection<DeclarationDescriptor> {
|
||||
//NOTE: descriptors should be in the same order they were serialized in
|
||||
// see MemberComparator
|
||||
@@ -200,33 +200,33 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
}
|
||||
|
||||
private fun addFunctionsAndProperties(
|
||||
result: MutableCollection<DeclarationDescriptor>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
location: LookupLocation
|
||||
result: MutableCollection<DeclarationDescriptor>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
location: LookupLocation
|
||||
) {
|
||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
|
||||
addMembers(
|
||||
getVariableNames(),
|
||||
nameFilter,
|
||||
result
|
||||
getVariableNames(),
|
||||
nameFilter,
|
||||
result
|
||||
) { getContributedVariables(it, location) }
|
||||
}
|
||||
|
||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
|
||||
addMembers(
|
||||
getFunctionNames(),
|
||||
nameFilter,
|
||||
result
|
||||
getFunctionNames(),
|
||||
nameFilter,
|
||||
result
|
||||
) { getContributedFunctions(it, location) }
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun addMembers(
|
||||
names: Collection<Name>,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
result: MutableCollection<DeclarationDescriptor>,
|
||||
descriptorsByName: (Name) -> Collection<DeclarationDescriptor>
|
||||
names: Collection<Name>,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
result: MutableCollection<DeclarationDescriptor>,
|
||||
descriptorsByName: (Name) -> Collection<DeclarationDescriptor>
|
||||
) {
|
||||
val subResult = ArrayList<DeclarationDescriptor>()
|
||||
for (name in names) {
|
||||
@@ -240,17 +240,17 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
}
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? =
|
||||
when {
|
||||
hasClass(name) -> deserializeClass(name)
|
||||
name in typeAliasNames -> typeAliasByName(name)
|
||||
else -> null
|
||||
}
|
||||
when {
|
||||
hasClass(name) -> deserializeClass(name)
|
||||
name in typeAliasNames -> typeAliasByName(name)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun deserializeClass(name: Name): ClassDescriptor? =
|
||||
c.components.deserializeClass(createClassId(name))
|
||||
c.components.deserializeClass(createClassId(name))
|
||||
|
||||
protected open fun hasClass(name: Name): Boolean =
|
||||
name in classNames
|
||||
name in classNames
|
||||
|
||||
protected abstract fun createClassId(name: Name): ClassId
|
||||
|
||||
|
||||
+15
-14
@@ -32,29 +32,30 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
|
||||
|
||||
open class DeserializedPackageMemberScope(
|
||||
private val packageDescriptor: PackageFragmentDescriptor,
|
||||
proto: ProtoBuf.Package,
|
||||
nameResolver: NameResolver,
|
||||
containerSource: DeserializedContainerSource?,
|
||||
components: DeserializationComponents,
|
||||
classNames: () -> Collection<Name>
|
||||
private val packageDescriptor: PackageFragmentDescriptor,
|
||||
proto: ProtoBuf.Package,
|
||||
nameResolver: NameResolver,
|
||||
containerSource: DeserializedContainerSource?,
|
||||
components: DeserializationComponents,
|
||||
classNames: () -> Collection<Name>
|
||||
) : DeserializedMemberScope(
|
||||
components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable),
|
||||
VersionRequirementTable.create(proto.versionRequirementTable), containerSource),
|
||||
proto.functionList, proto.propertyList, proto.typeAliasList, classNames
|
||||
components.createContext(
|
||||
packageDescriptor, nameResolver, TypeTable(proto.typeTable),
|
||||
VersionRequirementTable.create(proto.versionRequirementTable), containerSource
|
||||
),
|
||||
proto.functionList, proto.propertyList, proto.typeAliasList, classNames
|
||||
) {
|
||||
private val packageFqName = packageDescriptor.fqName
|
||||
|
||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) +
|
||||
c.components.fictitiousClassDescriptorFactories.flatMap { it.getAllContributedClassesIfPossible(packageFqName) }
|
||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) =
|
||||
computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) +
|
||||
c.components.fictitiousClassDescriptorFactories.flatMap { it.getAllContributedClassesIfPossible(packageFqName) }
|
||||
|
||||
override fun hasClass(name: Name) =
|
||||
super.hasClass(name) || c.components.fictitiousClassDescriptorFactories.any { it.shouldCreateClass(packageFqName, name) }
|
||||
super.hasClass(name) || c.components.fictitiousClassDescriptorFactories.any { it.shouldCreateClass(packageFqName, name) }
|
||||
|
||||
override fun createClassId(name: Name) = ClassId(packageFqName, name)
|
||||
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
|
||||
recordLookup(name, location)
|
||||
return super.getContributedClassifier(name, location)
|
||||
|
||||
+5
-4
@@ -29,9 +29,9 @@ import org.jetbrains.kotlin.serialization.deserialization.getName
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class DeserializedTypeParameterDescriptor(
|
||||
private val c: DeserializationContext,
|
||||
private val proto: ProtoBuf.TypeParameter,
|
||||
index: Int
|
||||
private val c: DeserializationContext,
|
||||
private val proto: ProtoBuf.TypeParameter,
|
||||
index: Int
|
||||
) : AbstractLazyTypeParameterDescriptor(
|
||||
c.storageManager, c.containingDeclaration, c.nameResolver.getName(proto.name),
|
||||
ProtoEnumFlags.variance(proto.variance), proto.reified, index, SourceElement.NO_SOURCE, SupertypeLoopChecker.EMPTY
|
||||
@@ -51,5 +51,6 @@ class DeserializedTypeParameterDescriptor(
|
||||
}
|
||||
|
||||
override fun reportSupertypeLoopError(type: KotlinType) = throw IllegalStateException(
|
||||
"There should be no cycles for deserialized type parameters, but found for: $this")
|
||||
"There should be no cycles for deserialized type parameters, but found for: $this"
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user