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