Support a more optimized way of storing types in metadata

Together with almost every type now there's also an id which references a type
from a separate table. Storing such ids instead of Type messages will allow to
reduce the size of the metadata for files where types are used many times over
and over again. Currently only deserialization of such types is supported,
along with the former mechanism
This commit is contained in:
Alexander Udalov
2015-10-07 19:00:08 +03:00
parent bff6639e2d
commit 82d2e623d3
32 changed files with 5583 additions and 796 deletions
File diff suppressed because it is too large Load Diff
@@ -92,8 +92,8 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
proto as ProtoBuf.Property
val nameResolver = container.nameResolver
val syntheticFunctionSignature = getPropertySignature(proto, nameResolver, synthetic = true)
val fieldSignature = getPropertySignature(proto, nameResolver, field = true)
val syntheticFunctionSignature = getPropertySignature(proto, nameResolver, container.typeTable, synthetic = true)
val fieldSignature = getPropertySignature(proto, nameResolver, container.typeTable, field = true)
val propertyAnnotations = syntheticFunctionSignature?.let { sig ->
findClassAndLoadMemberAnnotations(container, proto, sig)
@@ -106,7 +106,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
return loadPropertyAnnotations(propertyAnnotations, fieldAnnotations)
}
val signature = getCallableSignature(proto, container.nameResolver, kind) ?: return emptyList()
val signature = getCallableSignature(proto, container.nameResolver, container.typeTable, kind) ?: return emptyList()
return transformAnnotations(findClassAndLoadMemberAnnotations(container, proto, signature))
}
@@ -138,7 +138,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
parameterIndex: Int,
proto: ProtoBuf.ValueParameter
): List<A> {
val methodSignature = getCallableSignature(message, container.nameResolver, kind)
val methodSignature = getCallableSignature(message, container.nameResolver, container.typeTable, kind)
if (methodSignature != null) {
val index = if (proto.hasExtension(index)) proto.getExtension(index) else parameterIndex
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index)
@@ -153,7 +153,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
message: MessageLite,
kind: AnnotatedCallableKind
): List<A> {
val methodSignature = getCallableSignature(message, container.nameResolver, kind)
val methodSignature = getCallableSignature(message, container.nameResolver, container.typeTable, kind)
if (methodSignature != null) {
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, 0)
return findClassAndLoadMemberAnnotations(container, message, paramSignature)
@@ -168,7 +168,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
override fun loadPropertyConstant(container: ProtoContainer, proto: ProtoBuf.Property, expectedType: JetType): C? {
val nameResolver = container.nameResolver
val signature = getCallableSignature(proto, nameResolver, AnnotatedCallableKind.PROPERTY) ?: return null
val signature = getCallableSignature(proto, nameResolver, container.typeTable, AnnotatedCallableKind.PROPERTY) ?: return null
val kotlinClass = findClassWithAnnotationsAndInitializers(
container, getImplClassName(proto, nameResolver), isStaticFieldInOuter(proto)
@@ -279,6 +279,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
private fun getPropertySignature(
proto: ProtoBuf.Property,
nameResolver: NameResolver,
typeTable: TypeTable,
field: Boolean = false,
synthetic: Boolean = false
): MemberSignature? {
@@ -287,7 +288,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
else return null
if (field) {
val (name, desc) = JvmProtoBufUtil.getJvmFieldSignature(proto, nameResolver) ?: return null
val (name, desc) = JvmProtoBufUtil.getJvmFieldSignature(proto, nameResolver, typeTable) ?: return null
return MemberSignature.fromFieldNameAndDesc(name, desc)
}
else if (synthetic && signature.hasSyntheticMethod()) {
@@ -297,20 +298,25 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
return null
}
private fun getCallableSignature(proto: MessageLite, nameResolver: NameResolver, kind: AnnotatedCallableKind): MemberSignature? {
private fun getCallableSignature(
proto: MessageLite,
nameResolver: NameResolver,
typeTable: TypeTable,
kind: AnnotatedCallableKind
): MemberSignature? {
return when {
proto is ProtoBuf.Constructor -> {
MemberSignature.fromMethodNameAndDesc(JvmProtoBufUtil.getJvmConstructorSignature(proto, nameResolver) ?: return null)
MemberSignature.fromMethodNameAndDesc(JvmProtoBufUtil.getJvmConstructorSignature(proto, nameResolver, typeTable) ?: return null)
}
proto is ProtoBuf.Function -> {
MemberSignature.fromMethodNameAndDesc(JvmProtoBufUtil.getJvmMethodSignature(proto, nameResolver) ?: return null)
MemberSignature.fromMethodNameAndDesc(JvmProtoBufUtil.getJvmMethodSignature(proto, nameResolver, typeTable) ?: return null)
}
proto is ProtoBuf.Property && proto.hasExtension(propertySignature) -> {
val signature = proto.getExtension(propertySignature)
when (kind) {
AnnotatedCallableKind.PROPERTY_GETTER -> MemberSignature.fromMethod(nameResolver, signature.getter)
AnnotatedCallableKind.PROPERTY_SETTER -> MemberSignature.fromMethod(nameResolver, signature.setter)
AnnotatedCallableKind.PROPERTY -> getPropertySignature(proto, nameResolver, true, true)
AnnotatedCallableKind.PROPERTY -> getPropertySignature(proto, nameResolver, typeTable, true, true)
else -> null
}
}
@@ -25,7 +25,8 @@ import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
import org.jetbrains.kotlin.serialization.ClassData
import org.jetbrains.kotlin.serialization.PackageData
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.utils.singletonOrEmptyList
import java.io.ByteArrayInputStream
public object JvmProtoBufUtil {
@@ -60,7 +61,11 @@ public object JvmProtoBufUtil {
}
// returns JVM signature in the format: "equals(Ljava/lang/Object;)Z"
fun getJvmMethodSignature(proto: ProtoBuf.FunctionOrBuilder, nameResolver: NameResolver): String? {
fun getJvmMethodSignature(
proto: ProtoBuf.Function,
nameResolver: NameResolver,
typeTable: TypeTable
): String? {
val signature =
if (proto.hasExtension(JvmProtoBuf.methodSignature)) proto.getExtension(JvmProtoBuf.methodSignature) else null
val name = if (signature != null && signature.hasName()) signature.name else proto.name
@@ -68,18 +73,21 @@ public object JvmProtoBufUtil {
nameResolver.getString(signature.desc)
}
else {
val parameterTypes =
(if (proto.hasReceiverType()) listOf(proto.receiverType) else listOf()) + proto.valueParameterList.map { it.type }
val parameterTypes = proto.receiverType(typeTable).singletonOrEmptyList() + proto.valueParameterList.map { it.type(typeTable) }
val parametersDesc = parameterTypes.map { mapTypeDefault(it, nameResolver) ?: return null }
val returnTypeDesc = mapTypeDefault(proto.returnType, nameResolver) ?: return null
val returnTypeDesc = mapTypeDefault(proto.returnType(typeTable), nameResolver) ?: return null
parametersDesc.joinToString(separator = "", prefix = "(", postfix = ")") + returnTypeDesc
}
return nameResolver.getString(name) + desc
}
fun getJvmConstructorSignature(proto: ProtoBuf.ConstructorOrBuilder, nameResolver: NameResolver): String? {
fun getJvmConstructorSignature(
proto: ProtoBuf.Constructor,
nameResolver: NameResolver,
typeTable: TypeTable
): String? {
val signature =
if (proto.hasExtension(JvmProtoBuf.constructorSignature)) proto.getExtension(JvmProtoBuf.constructorSignature) else null
val desc = if (signature != null && signature.hasDesc()) {
@@ -87,13 +95,17 @@ public object JvmProtoBufUtil {
}
else {
proto.valueParameterList.map {
mapTypeDefault(it.type, nameResolver) ?: return null
mapTypeDefault(it.type(typeTable), nameResolver) ?: return null
}.joinToString(separator = "", prefix = "(", postfix = ")V")
}
return "<init>" + desc
}
fun getJvmFieldSignature(proto: ProtoBuf.Property, nameResolver: NameResolver): PropertySignature? {
fun getJvmFieldSignature(
proto: ProtoBuf.Property,
nameResolver: NameResolver,
typeTable: TypeTable
): PropertySignature? {
val signature =
if (proto.hasExtension(JvmProtoBuf.propertySignature)) proto.getExtension(JvmProtoBuf.propertySignature) else return null
val field =
@@ -102,7 +114,7 @@ public object JvmProtoBufUtil {
val name = if (field != null && field.hasName()) field.name else proto.name
val desc =
if (field != null && field.hasDesc()) nameResolver.getString(field.desc)
else mapTypeDefault(proto.returnType, nameResolver) ?: return null
else mapTypeDefault(proto.returnType(typeTable), nameResolver) ?: return null
return PropertySignature(nameResolver.getString(name), desc)
}
+31 -4
View File
@@ -105,7 +105,10 @@ message Type {
}
optional Projection projection = 1 [default = INV];
optional Type type = 2; // when projection is STAR, no type is written, otherwise type must be specified
// When projection is STAR, no type is written, otherwise type must be specified
optional Type type = 2;
optional int32 type_id = 3;
}
repeated Argument argument = 2;
@@ -117,6 +120,7 @@ message Type {
optional int32 flexible_type_capabilities_id = 4 [(string_id_in_table) = true];
optional Type flexible_upper_bound = 5;
optional int32 flexible_upper_bound_id = 8;
// Only one of the following values should be present
@@ -141,6 +145,7 @@ message TypeParameter {
optional Variance variance = 4 [default = INV];
repeated Type upper_bound = 5;
repeated int32 upper_bound_id = 6;
}
message Class {
@@ -169,7 +174,9 @@ message Class {
optional int32 companion_object_name = 4 [(name_id_in_table) = true];
repeated TypeParameter type_parameter = 5;
repeated Type supertype = 6;
repeated int32 supertype_id = 2 [packed = true];
repeated int32 nested_class_name = 7 [packed = true, (name_id_in_table) = true];
@@ -179,6 +186,8 @@ message Class {
repeated int32 enum_entry = 12 [packed = true, (name_id_in_table) = true];
optional TypeTable type_table = 30;
extensions 100 to 199;
}
@@ -186,9 +195,19 @@ message Package {
repeated Function function = 3;
repeated Property property = 4;
optional TypeTable type_table = 30;
extensions 100 to 199;
}
message TypeTable {
repeated Type type = 1;
// Index starting from which all types are nullable, or nothing if all types in this table are non-null.
// Note that the 'nullable' field of Type messages is ignored and shouldn't be written because it wastes too much space
optional int32 first_nullable = 2 [default = -1];
}
message Constructor {
/*
hasAnnotations
@@ -215,14 +234,18 @@ message Function {
required int32 name = 2 [(name_id_in_table) = true];
required Type return_type = 3;
optional Type return_type = 3;
optional int32 return_type_id = 7;
repeated TypeParameter type_parameter = 4;
optional Type receiver_type = 5;
optional int32 receiver_type_id = 8;
repeated ValueParameter value_parameter = 6;
optional TypeTable type_table = 30;
extensions 100 to 199;
}
@@ -243,11 +266,13 @@ message Property {
required int32 name = 2 [(name_id_in_table) = true];
required Type return_type = 3;
optional Type return_type = 3;
optional int32 return_type_id = 9;
repeated TypeParameter type_parameter = 4;
optional Type receiver_type = 5;
optional int32 receiver_type_id = 10;
optional ValueParameter setter_value_parameter = 6;
@@ -272,9 +297,11 @@ message ValueParameter {
required int32 name = 2 [(name_id_in_table) = true];
required Type type = 3;
optional Type type = 3;
optional int32 type_id = 5;
optional Type vararg_element_type = 4;
optional int32 vararg_element_type_id = 6;
extensions 100 to 199;
}
File diff suppressed because it is too large Load Diff
@@ -56,7 +56,7 @@ public class ClassDeserializer(private val components: DeserializationComponents
if (!fragment.hasTopLevelClass(classId.shortClassName)) return null
}
components.createContext(fragment, nameResolver)
components.createContext(fragment, nameResolver, TypeTable(classProto.typeTable))
}
return DeserializedClassDescriptor(outerContext, classProto, nameResolver, sourceElement)
@@ -42,25 +42,26 @@ public class MemberDeserializer(private val c: DeserializationContext) {
Flags.IS_VAR.get(flags),
c.nameResolver.getName(proto.getName()),
Deserialization.memberKind(Flags.MEMBER_KIND.get(flags)),
Flags.IS_LATEINIT.get(flags),
Flags.IS_CONST.get(flags),
proto,
c.nameResolver,
Flags.IS_LATEINIT.get(flags),
Flags.IS_CONST.get(flags)
c.typeTable
)
val local = c.childContext(property, proto.getTypeParameterList())
val hasGetter = Flags.HAS_GETTER.get(flags)
val receiverAnnotations = if (hasGetter && proto.hasReceiverType())
val receiverAnnotations = if (hasGetter && (proto.hasReceiverType() || proto.hasReceiverTypeId()))
getReceiverParameterAnnotations(proto, AnnotatedCallableKind.PROPERTY_GETTER)
else
Annotations.EMPTY
property.setType(
local.typeDeserializer.type(proto.getReturnType()),
local.typeDeserializer.type(proto.returnType(c.typeTable)),
local.typeDeserializer.ownTypeParameters,
getDispatchReceiverParameter(),
if (proto.hasReceiverType()) local.typeDeserializer.type(proto.getReceiverType(), receiverAnnotations) else null
proto.receiverType(c.typeTable)?.let { local.typeDeserializer.type(it, receiverAnnotations) }
)
val getter = if (hasGetter) {
@@ -130,18 +131,18 @@ public class MemberDeserializer(private val c: DeserializationContext) {
}
public fun loadFunction(proto: ProtoBuf.Function): FunctionDescriptor {
val annotations = getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION)
val receiverAnnotations = if (proto.hasReceiverType())
val annotations = getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION)
val receiverAnnotations = if (proto.hasReceiverType() || proto.hasReceiverTypeId())
getReceiverParameterAnnotations(proto, AnnotatedCallableKind.FUNCTION)
else Annotations.EMPTY
val function = DeserializedSimpleFunctionDescriptor.create(c.containingDeclaration, proto, c.nameResolver, annotations)
val local = c.childContext(function, proto.getTypeParameterList())
val function = DeserializedSimpleFunctionDescriptor.create(c.containingDeclaration, annotations, proto, c.nameResolver, c.typeTable)
val local = c.childContext(function, proto.typeParameterList)
function.initialize(
if (proto.hasReceiverType()) local.typeDeserializer.type(proto.getReceiverType(), receiverAnnotations) else null,
proto.receiverType(c.typeTable)?.let { local.typeDeserializer.type(it, receiverAnnotations) },
getDispatchReceiverParameter(),
local.typeDeserializer.ownTypeParameters,
local.memberDeserializer.valueParameters(proto.valueParameterList, proto, AnnotatedCallableKind.FUNCTION),
local.typeDeserializer.type(proto.returnType),
local.typeDeserializer.type(proto.returnType(c.typeTable)),
Deserialization.modality(Flags.MODALITY.get(proto.flags)),
Deserialization.visibility(Flags.VISIBILITY.get(proto.flags))
)
@@ -158,7 +159,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
val classDescriptor = c.containingDeclaration as ClassDescriptor
val descriptor = DeserializedConstructorDescriptor(
classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION),
isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver
isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver, c.typeTable
)
val local = c.childContext(descriptor, listOf())
descriptor.initialize(
@@ -209,9 +210,9 @@ public class MemberDeserializer(private val c: DeserializationContext) {
callableDescriptor, null, i,
containerOfCallable?.let { getParameterAnnotations(it, callable, kind, i, proto) } ?: Annotations.EMPTY,
c.nameResolver.getName(proto.name),
c.typeDeserializer.type(proto.type),
c.typeDeserializer.type(proto.type(c.typeTable)),
Flags.DECLARES_DEFAULT_VALUE.get(flags),
if (proto.hasVarargElementType()) c.typeDeserializer.type(proto.varargElementType) else null,
proto.varargElementType(c.typeTable)?.let { c.typeDeserializer.type(it) },
SourceElement.NO_SOURCE
)
}.toReadOnlyList()
@@ -230,8 +231,8 @@ public class MemberDeserializer(private val c: DeserializationContext) {
}
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when(this) {
is PackageFragmentDescriptor -> ProtoContainer(null, fqName, c.nameResolver)
is DeserializedClassDescriptor -> ProtoContainer(classProto, null, c.nameResolver)
is PackageFragmentDescriptor -> ProtoContainer(null, fqName, c.nameResolver, c.typeTable)
is DeserializedClassDescriptor -> ProtoContainer(classProto, null, c.nameResolver, c.typeTable)
else -> null // TODO: support annotations on lambdas and their parameters
}
}
@@ -22,7 +22,8 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
public data class ProtoContainer(
val classProto: ProtoBuf.Class?,
val packageFqName: FqName?,
val nameResolver: NameResolver
val nameResolver: NameResolver,
val typeTable: TypeTable
) {
init {
assert((classProto != null) xor (packageFqName != null))
@@ -42,7 +42,7 @@ public class TypeDeserializer(
else {
val result = LinkedHashMap<Int, TypeParameterDescriptor>()
for ((index, proto) in typeParameterProtos.withIndex()) {
result[proto.getId()] = DeserializedTypeParameterDescriptor(c, proto, index)
result[proto.id] = DeserializedTypeParameterDescriptor(c, proto, index)
}
result
}
@@ -51,18 +51,16 @@ public class TypeDeserializer(
val ownTypeParameters: List<TypeParameterDescriptor>
get() = typeParameterDescriptors().values().toReadOnlyList()
// TODO: don't load identical types from TypeTable more than once
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): JetType {
if (proto.hasFlexibleTypeCapabilitiesId()) {
val id = c.nameResolver.getString(proto.getFlexibleTypeCapabilitiesId())
val capabilities = c.components.flexibleTypeCapabilitiesDeserializer.capabilitiesById(id)
if (capabilities == null) {
return ErrorUtils.createErrorType("${DeserializedType(c, proto)}: Capabilities not found for id $id")
}
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
val capabilities = c.components.flexibleTypeCapabilitiesDeserializer.capabilitiesById(id) ?:
return ErrorUtils.createErrorType("${DeserializedType(c, proto)}: Capabilities not found for id $id")
return DelegatingFlexibleType.create(
DeserializedType(c, proto),
DeserializedType(c, proto.getFlexibleUpperBound()),
DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!),
capabilities
)
}
@@ -95,7 +93,7 @@ public class TypeDeserializer(
private fun computeClassDescriptor(fqNameIndex: Int): ClassDescriptor? {
val id = c.nameResolver.getClassId(fqNameIndex)
if (id.isLocal()) {
if (id.isLocal) {
// Local classes can't be found in scopes
return c.components.localClassResolver.resolveLocalClass(id)
}
@@ -103,12 +101,18 @@ public class TypeDeserializer(
}
fun typeArgument(parameter: TypeParameterDescriptor?, typeArgumentProto: ProtoBuf.Type.Argument): TypeProjection {
return if (typeArgumentProto.getProjection() == ProtoBuf.Type.Argument.Projection.STAR)
if (parameter == null)
TypeBasedStarProjectionImpl(c.components.moduleDescriptor.builtIns.getNullableAnyType())
if (typeArgumentProto.projection == ProtoBuf.Type.Argument.Projection.STAR) {
return if (parameter == null)
TypeBasedStarProjectionImpl(c.components.moduleDescriptor.builtIns.nullableAnyType)
else
StarProjectionImpl(parameter)
else TypeProjectionImpl(Deserialization.variance(typeArgumentProto.getProjection()), type(typeArgumentProto.getType()))
}
val variance = Deserialization.variance(typeArgumentProto.projection)
val type = typeArgumentProto.type(c.typeTable) ?:
return TypeProjectionImpl(ErrorUtils.createErrorType("No type recorded"))
return TypeProjectionImpl(variance, type(type))
}
override fun toString() = debugName + (if (parent == null) "" else ". Child of ${parent.debugName}")
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.serialization.ProtoBuf
class TypeTable(typeTable: ProtoBuf.TypeTable) {
val types: List<ProtoBuf.Type> = run {
val originalTypes = typeTable.typeList
if (typeTable.hasFirstNullable()) {
val firstNullable = typeTable.firstNullable
typeTable.typeList.mapIndexed { i, type ->
if (i >= firstNullable) {
type.toBuilder().setNullable(true).build()
}
else type
}
}
else originalTypes
}
operator fun get(index: Int) = types[index]
}
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.storage.StorageManager
public class DeserializationComponents(
class DeserializationComponents(
val storageManager: StorageManager,
val moduleDescriptor: ModuleDescriptor,
val classDataFinder: ClassDataFinder,
@@ -37,19 +37,24 @@ public class DeserializationComponents(
val typeCapabilitiesLoader: TypeCapabilitiesLoader = TypeCapabilitiesLoader.NONE,
val additionalSupertypes: AdditionalSupertypes = AdditionalSupertypes.None
) {
public val classDeserializer: ClassDeserializer = ClassDeserializer(this)
val classDeserializer: ClassDeserializer = ClassDeserializer(this)
public fun deserializeClass(classId: ClassId): ClassDescriptor? = classDeserializer.deserializeClass(classId)
fun deserializeClass(classId: ClassId): ClassDescriptor? = classDeserializer.deserializeClass(classId)
public fun createContext(descriptor: PackageFragmentDescriptor, nameResolver: NameResolver): DeserializationContext =
DeserializationContext(this, nameResolver, descriptor, parentTypeDeserializer = null, typeParameters = listOf())
fun createContext(
descriptor: PackageFragmentDescriptor,
nameResolver: NameResolver,
typeTable: TypeTable
): DeserializationContext =
DeserializationContext(this, nameResolver, descriptor, typeTable, parentTypeDeserializer = null, typeParameters = listOf())
}
public class DeserializationContext(
public val components: DeserializationComponents,
public val nameResolver: NameResolver,
public val containingDeclaration: DeclarationDescriptor,
class DeserializationContext(
val components: DeserializationComponents,
val nameResolver: NameResolver,
val containingDeclaration: DeclarationDescriptor,
val typeTable: TypeTable,
parentTypeDeserializer: TypeDeserializer?,
typeParameters: List<ProtoBuf.TypeParameter>
) {
@@ -63,8 +68,11 @@ public class DeserializationContext(
fun childContext(
descriptor: DeclarationDescriptor,
typeParameterProtos: List<ProtoBuf.TypeParameter>,
nameResolver: NameResolver = this.nameResolver
nameResolver: NameResolver = this.nameResolver,
typeTable: TypeTable = this.typeTable
) = DeserializationContext(
components, nameResolver, descriptor, parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos
components, nameResolver, descriptor, typeTable,
parentTypeDeserializer = this.typeDeserializer,
typeParameters = typeParameterProtos
)
}
@@ -19,9 +19,12 @@ package org.jetbrains.kotlin.serialization.deserialization.descriptors
import com.google.protobuf.MessageLite
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
interface DeserializedCallableMemberDescriptor : CallableMemberDescriptor {
val proto: MessageLite
val nameResolver: NameResolver
val typeTable: TypeTable
}
@@ -30,10 +30,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.Deserialization
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import org.jetbrains.kotlin.serialization.deserialization.DeserializedType
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.upperIfFlexible
@@ -58,7 +55,7 @@ public class DeserializedClassDescriptor(
private val isCompanion = kindFromProto == ProtoBuf.Class.Kind.COMPANION_OBJECT
private val isInner = Flags.IS_INNER.get(classProto.getFlags())
val c = outerContext.childContext(this, classProto.getTypeParameterList(), nameResolver)
val c = outerContext.childContext(this, classProto.typeParameterList, nameResolver, TypeTable(classProto.typeTable))
private val classId = nameResolver.getClassId(classProto.getFqName())
@@ -138,7 +135,7 @@ public class DeserializedClassDescriptor(
val result = ArrayList<JetType>(classProto.supertypeCount)
val unresolved = ArrayList<DeserializedType>(0)
for (supertypeProto in classProto.supertypeList) {
for (supertypeProto in classProto.supertypes(c.typeTable)) {
val supertype = c.typeDeserializer.type(supertypeProto)
if (supertype.isError) {
unresolved.add(supertype.upperIfFlexible() as? DeserializedType ?: error("Not a deserialized type: $supertype"))
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
public class DeserializedConstructorDescriptor(
containingDeclaration: ClassDescriptor,
@@ -29,7 +30,8 @@ public class DeserializedConstructorDescriptor(
isPrimary: Boolean,
kind: CallableMemberDescriptor.Kind,
override val proto: ProtoBuf.Constructor,
override val nameResolver: NameResolver
override val nameResolver: NameResolver,
override val typeTable: TypeTable
) : ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, SourceElement.NO_SOURCE),
DeserializedCallableMemberDescriptor {
@@ -39,7 +41,8 @@ public class DeserializedConstructorDescriptor(
kind: CallableMemberDescriptor.Kind
): DeserializedConstructorDescriptor {
return DeserializedConstructorDescriptor(
newOwner as ClassDescriptor, original as ConstructorDescriptor?, getAnnotations(), isPrimary, kind, proto, nameResolver
newOwner as ClassDescriptor, original as ConstructorDescriptor?,
annotations, isPrimary, kind, proto, nameResolver, typeTable
)
}
}
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import org.jetbrains.kotlin.serialization.deserialization.receiverType
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
@@ -38,11 +39,11 @@ public abstract class DeserializedMemberScope protected constructor(
private val functionProtos =
c.storageManager.createLazyValue {
groupByKey(filteredFunctionProtos(functionList), { it.name }) { it.hasReceiverType() }
groupByKey(filteredFunctionProtos(functionList), { it.name }) { it.receiverType(c.typeTable) != null }
}
private val propertyProtos =
c.storageManager.createLazyValue {
groupByKey(filteredPropertyProtos(propertyList), { it.name }) { it.hasReceiverType() }
groupByKey(filteredPropertyProtos(propertyList), { it.name }) { it.receiverType(c.typeTable) != null }
}
private val functions =
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.addIfNotNull
@@ -38,7 +39,10 @@ public open class DeserializedPackageMemberScope(
nameResolver: NameResolver,
components: DeserializationComponents,
classNames: () -> Collection<Name>
) : DeserializedMemberScope(components.createContext(packageDescriptor, nameResolver), proto.functionList, proto.propertyList) {
) : DeserializedMemberScope(
components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable)),
proto.functionList, proto.propertyList
) {
private val packageFqName = packageDescriptor.fqName
internal val classNames by c.storageManager.createLazyValue { classNames().toSet() }
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
class DeserializedPropertyDescriptor(
containingDeclaration: DeclarationDescriptor,
@@ -33,10 +34,11 @@ class DeserializedPropertyDescriptor(
isVar: Boolean,
name: Name,
kind: Kind,
lateInit: Boolean,
isConst: Boolean,
override val proto: ProtoBuf.Property,
override val nameResolver: NameResolver,
lateInit: Boolean,
isConst: Boolean
override val typeTable: TypeTable
) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations,
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, lateInit, isConst) {
@@ -49,6 +51,8 @@ class DeserializedPropertyDescriptor(
kind: Kind
): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor(
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, proto, nameResolver, isLateInit, isConst)
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, isLateInit, isConst,
proto, nameResolver, typeTable
)
}
}
@@ -30,11 +30,13 @@ import org.jetbrains.kotlin.serialization.Flags;
import org.jetbrains.kotlin.serialization.ProtoBuf;
import org.jetbrains.kotlin.serialization.deserialization.Deserialization;
import org.jetbrains.kotlin.serialization.deserialization.NameResolver;
import org.jetbrains.kotlin.serialization.deserialization.TypeTable;
public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescriptorImpl implements DeserializedCallableMemberDescriptor {
private final ProtoBuf.Function proto;
private final NameResolver nameResolver;
private final TypeTable typeTable;
private DeserializedSimpleFunctionDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@@ -43,11 +45,13 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
@NotNull Name name,
@NotNull Kind kind,
@NotNull ProtoBuf.Function proto,
@NotNull NameResolver nameResolver
@NotNull NameResolver nameResolver,
@NotNull TypeTable typeTable
) {
super(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE);
this.proto = proto;
this.nameResolver = nameResolver;
this.typeTable = typeTable;
}
@NotNull
@@ -64,7 +68,8 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
getName(),
kind,
proto,
nameResolver
nameResolver,
typeTable
);
}
@@ -86,12 +91,19 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
return nameResolver;
}
@NotNull
@Override
public TypeTable getTypeTable() {
return typeTable;
}
@NotNull
public static DeserializedSimpleFunctionDescriptor create(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Annotations annotations,
@NotNull ProtoBuf.Function proto,
@NotNull NameResolver nameResolver,
@NotNull Annotations annotations
@NotNull TypeTable typeTable
) {
return new DeserializedSimpleFunctionDescriptor(
containingDeclaration,
@@ -100,7 +112,8 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
nameResolver.getName(proto.getName()),
Deserialization.memberKind(Flags.MEMBER_KIND.get(proto.getFlags())),
proto,
nameResolver
nameResolver,
typeTable
);
}
}
@@ -21,13 +21,12 @@ import org.jetbrains.kotlin.descriptors.SourceElement;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
import org.jetbrains.kotlin.serialization.ProtoBuf;
import org.jetbrains.kotlin.serialization.deserialization.Deserialization;
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext;
import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer;
import org.jetbrains.kotlin.serialization.deserialization.*;
import org.jetbrains.kotlin.types.JetType;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
@@ -35,6 +34,7 @@ import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getB
public class DeserializedTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor {
private final ProtoBuf.TypeParameter proto;
private final TypeDeserializer typeDeserializer;
private final TypeTable typeTable;
public DeserializedTypeParameterDescriptor(@NotNull DeserializationContext c, @NotNull ProtoBuf.TypeParameter proto, int index) {
super(c.getStorageManager(),
@@ -46,16 +46,18 @@ public class DeserializedTypeParameterDescriptor extends AbstractLazyTypeParamet
SourceElement.NO_SOURCE);
this.proto = proto;
this.typeDeserializer = c.getTypeDeserializer();
this.typeTable = c.getTypeTable();
}
@NotNull
@Override
protected Set<JetType> resolveUpperBounds() {
if (proto.getUpperBoundCount() == 0) {
List<ProtoBuf.Type> upperBounds = ProtoTypeTableUtilKt.upperBounds(proto, typeTable);
if (upperBounds.isEmpty()) {
return Collections.singleton(getBuiltIns(this).getDefaultBound());
}
Set<JetType> result = new LinkedHashSet<JetType>(proto.getUpperBoundCount());
for (ProtoBuf.Type upperBound : proto.getUpperBoundList()) {
Set<JetType> result = new LinkedHashSet<JetType>(upperBounds.size());
for (ProtoBuf.Type upperBound : upperBounds) {
result.add(typeDeserializer.type(upperBound, Annotations.Companion.getEMPTY()));
}
return result;
@@ -0,0 +1,80 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.utils.ifEmpty
fun ProtoBuf.Class.supertypes(typeTable: TypeTable): List<ProtoBuf.Type> {
return supertypeList.ifEmpty { supertypeIdList.map { typeTable[it] } }
}
fun ProtoBuf.Type.Argument.type(typeTable: TypeTable): ProtoBuf.Type? {
return when {
hasType() -> type
hasTypeId() -> typeTable[typeId]
else -> null
}
}
fun ProtoBuf.Type.flexibleUpperBound(typeTable: TypeTable): ProtoBuf.Type? {
return when {
hasFlexibleUpperBound() -> flexibleUpperBound
hasFlexibleUpperBoundId() -> typeTable[flexibleUpperBoundId]
else -> null
}
}
fun ProtoBuf.TypeParameter.upperBounds(typeTable: TypeTable): List<ProtoBuf.Type> {
return upperBoundList.ifEmpty { upperBoundIdList.map { typeTable[it] } }
}
fun ProtoBuf.Function.returnType(typeTable: TypeTable): ProtoBuf.Type {
return if (hasReturnType()) returnType else typeTable[returnTypeId]
}
fun ProtoBuf.Function.receiverType(typeTable: TypeTable): ProtoBuf.Type? {
return when {
hasReceiverType() -> receiverType
hasReceiverTypeId() -> typeTable[receiverTypeId]
else -> null
}
}
fun ProtoBuf.Property.returnType(typeTable: TypeTable): ProtoBuf.Type {
return if (hasReturnType()) returnType else typeTable[returnTypeId]
}
fun ProtoBuf.Property.receiverType(typeTable: TypeTable): ProtoBuf.Type? {
return when {
hasReceiverType() -> receiverType
hasReceiverTypeId() -> typeTable[receiverTypeId]
else -> null
}
}
fun ProtoBuf.ValueParameter.type(typeTable: TypeTable): ProtoBuf.Type {
return if (hasType()) type else typeTable[typeId]
}
fun ProtoBuf.ValueParameter.varargElementType(typeTable: TypeTable): ProtoBuf.Type? {
return when {
hasVarargElementType() -> varargElementType
hasVarargElementTypeId() -> typeTable[varargElementTypeId]
else -> null
}
}
@@ -47,7 +47,7 @@ internal abstract class DescriptorBasedProperty<out R> protected constructor(
val jvmSignature = RuntimeTypeMapper.mapPropertySignature(descriptor)
when (jvmSignature) {
is KotlinProperty -> {
JvmProtoBufUtil.getJvmFieldSignature(jvmSignature.proto, jvmSignature.nameResolver)?.let {
JvmProtoBufUtil.getJvmFieldSignature(jvmSignature.proto, jvmSignature.nameResolver, jvmSignature.typeTable)?.let {
container.findFieldBySignature(jvmSignature.proto, jvmSignature.nameResolver, it.name)
}
}
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
@@ -100,7 +101,8 @@ internal sealed class JvmPropertySignature {
val descriptor: PropertyDescriptor,
val proto: ProtoBuf.Property,
val signature: JvmProtoBuf.JvmPropertySignature,
val nameResolver: NameResolver
val nameResolver: NameResolver,
val typeTable: TypeTable
) : JvmPropertySignature() {
private val string: String
@@ -110,7 +112,7 @@ internal sealed class JvmPropertySignature {
}
else {
val (name, desc) =
JvmProtoBufUtil.getJvmFieldSignature(proto, nameResolver) ?:
JvmProtoBufUtil.getJvmFieldSignature(proto, nameResolver, typeTable) ?:
throw KotlinReflectionInternalError("No field signature for property: $descriptor")
val moduleSuffix =
@@ -154,12 +156,12 @@ internal object RuntimeTypeMapper {
val proto = function.proto
if (proto is ProtoBuf.Function) {
JvmProtoBufUtil.getJvmMethodSignature(proto, function.nameResolver)?.let { signature ->
JvmProtoBufUtil.getJvmMethodSignature(proto, function.nameResolver, function.typeTable)?.let { signature ->
return JvmFunctionSignature.KotlinFunction(signature)
}
}
if (proto is ProtoBuf.Constructor) {
JvmProtoBufUtil.getJvmConstructorSignature(proto, function.nameResolver)?.let { signature ->
JvmProtoBufUtil.getJvmConstructorSignature(proto, function.nameResolver, function.typeTable)?.let { signature ->
return JvmFunctionSignature.KotlinConstructor(signature)
}
}
@@ -191,7 +193,7 @@ internal object RuntimeTypeMapper {
throw KotlinReflectionInternalError("No metadata found for $property")
}
return JvmPropertySignature.KotlinProperty(
property, proto, proto.getExtension(JvmProtoBuf.propertySignature), property.nameResolver
property, proto, proto.getExtension(JvmProtoBuf.propertySignature), property.nameResolver, property.typeTable
)
}
else if (property is JavaPropertyDescriptor) {
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.load.kotlin.JvmNameResolver
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import org.jetbrains.kotlin.serialization.deserialization.MemberDeserializer
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.jvm.BitEncoding
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
@@ -43,8 +44,10 @@ public fun <R> Function<R>.reflect(): KFunction<R>? {
)
val proto = ProtoBuf.Function.parseFrom(input, JvmProtoBufUtil.EXTENSION_REGISTRY)
val moduleData = javaClass.getOrCreateModule()
val context = DeserializationContext(moduleData.deserialization, nameResolver, moduleData.module,
parentTypeDeserializer = null, typeParameters = listOf())
val context = DeserializationContext(
moduleData.deserialization, nameResolver, moduleData.module,
typeTable = TypeTable(proto.typeTable), parentTypeDeserializer = null, typeParameters = listOf()
)
val descriptor = MemberDeserializer(context).loadFunction(proto)
@Suppress("UNCHECKED_CAST")
return KFunctionImpl(EmptyContainerForLocal, descriptor) as KFunction<R>
@@ -31,6 +31,8 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.MemberKind
import org.jetbrains.kotlin.serialization.ProtoBuf.Modality
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.receiverType
import org.jetbrains.kotlin.serialization.deserialization.returnType
fun createCallableStubs(
parentStub: StubElement<out PsiElement>,
@@ -118,10 +120,10 @@ private class FunctionClsStubBuilder(
private val functionProto: ProtoBuf.Function
) : CallableClsStubBuilder(parent, outerContext, protoContainer, functionProto.typeParameterList) {
override val receiverType: ProtoBuf.Type?
get() = if (functionProto.hasReceiverType()) functionProto.receiverType else null
get() = functionProto.receiverType(c.typeTable)
override val returnType: ProtoBuf.Type?
get() = if (functionProto.hasReturnType()) functionProto.returnType else null
get() = functionProto.returnType(c.typeTable)
override fun createValueParameterList() {
typeStubBuilder.createValueParameterListStub(callableStub, functionProto, functionProto.valueParameterList, protoContainer)
@@ -165,10 +167,10 @@ private class PropertyClsStubBuilder(
private val isVar = Flags.IS_VAR.get(propertyProto.flags)
override val receiverType: ProtoBuf.Type?
get() = if (propertyProto.hasReceiverType()) propertyProto.receiverType else null
get() = propertyProto.receiverType(c.typeTable)
override val returnType: ProtoBuf.Type?
get() = if (propertyProto.hasReturnType()) propertyProto.returnType else null
get() = propertyProto.returnType(c.typeTable)
override fun createValueParameterList() {
}
@@ -37,6 +37,8 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.deserialization.supertypes
fun createClassStub(parent: StubElement<out PsiElement>, classProto: ProtoBuf.Class, classId: ClassId, context: ClsStubBuilderContext) {
ClassClsStubBuilder(parent, classProto, classId, context).build()
@@ -48,11 +50,11 @@ private class ClassClsStubBuilder(
private val classId: ClassId,
private val outerContext: ClsStubBuilderContext
) {
private val c = outerContext.child(classProto.getTypeParameterList(), classId.getShortClassName())
private val c = outerContext.child(classProto.typeParameterList, classId.shortClassName, TypeTable(classProto.typeTable))
private val typeStubBuilder = TypeClsStubBuilder(c)
private val classKind = Flags.CLASS_KIND[classProto.getFlags()]
private val classKind = Flags.CLASS_KIND[classProto.flags]
private val supertypeIds = run {
val supertypeIds = classProto.supertypeList.map { c.nameResolver.getClassId(it.className) }
val supertypeIds = classProto.supertypes(c.typeTable).map { c.nameResolver.getClassId(it.className) }
//empty supertype list if single supertype is Any
if (supertypeIds.singleOrNull()?.let { KotlinBuiltIns.isAny(it.asSingleFqName().toUnsafe()) } ?: false) {
listOf()
@@ -133,7 +135,7 @@ private class ClassClsStubBuilder(
val primaryConstructorProto = classProto.constructorList.find { !Flags.IS_SECONDARY.get(it.flags) } ?: return
createConstructorStub(classOrObjectStub, primaryConstructorProto, c, ProtoContainer(classProto, null, c.nameResolver))
createConstructorStub(classOrObjectStub, primaryConstructorProto, c, ProtoContainer(classProto, null, c.nameResolver, c.typeTable))
}
private fun createDelegationSpecifierList() {
@@ -143,7 +145,7 @@ private class ClassClsStubBuilder(
val delegationSpecifierListStub =
KotlinPlaceHolderStubImpl<JetDelegationSpecifierList>(classOrObjectStub, JetStubElementTypes.DELEGATION_SPECIFIER_LIST)
classProto.getSupertypeList().forEach { type ->
classProto.supertypes(c.typeTable).forEach { type ->
val superClassStub = KotlinPlaceHolderStubImpl<JetDelegatorToSuperClass>(
delegationSpecifierListStub, JetStubElementTypes.DELEGATOR_SUPER_CLASS
)
@@ -186,7 +188,7 @@ private class ClassClsStubBuilder(
}
private fun createCallableMemberStubs(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
val container = ProtoContainer(classProto, null, c.nameResolver)
val container = ProtoContainer(classProto, null, c.nameResolver, c.typeTable)
for (secondaryConstructorProto in classProto.constructorList) {
if (Flags.IS_SECONDARY.get(secondaryConstructorProto.flags)) {
@@ -216,6 +218,6 @@ private class ClassClsStubBuilder(
private fun createNestedClassStub(classBody: StubElement<out PsiElement>, nestedClassId: ClassId) {
val classDataWithSource = c.components.classDataFinder.findClassData(nestedClassId)!!
val (nameResolver, classProto) = classDataWithSource.classData
createClassStub(classBody, classProto, nestedClassId, c.child(nameResolver))
createClassStub(classBody, classProto, nestedClassId, c.child(nameResolver, TypeTable(classProto.typeTable)))
}
}
@@ -25,10 +25,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.AnnotationAndConstantLoader
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
import org.jetbrains.kotlin.storage.LockBasedStorageManager
@@ -40,9 +37,10 @@ class ClsStubBuilderComponents(
) {
fun createContext(
nameResolver: NameResolver,
packageFqName: FqName
packageFqName: FqName,
typeTable: TypeTable
): ClsStubBuilderContext {
return ClsStubBuilderContext(this, nameResolver, packageFqName, EmptyTypeParameters)
return ClsStubBuilderContext(this, nameResolver, packageFqName, EmptyTypeParameters, typeTable)
}
}
@@ -71,24 +69,31 @@ class ClsStubBuilderContext(
val components: ClsStubBuilderComponents,
val nameResolver: NameResolver,
val containerFqName: FqName,
val typeParameters: TypeParameters
val typeParameters: TypeParameters,
val typeTable: TypeTable
)
internal fun ClsStubBuilderContext.child(typeParameterList: List<ProtoBuf.TypeParameter>, name: Name? = null): ClsStubBuilderContext {
internal fun ClsStubBuilderContext.child(
typeParameterList: List<ProtoBuf.TypeParameter>,
name: Name? = null,
typeTable: TypeTable = this.typeTable
): ClsStubBuilderContext {
return ClsStubBuilderContext(
this.components,
this.nameResolver,
if (name != null) this.containerFqName.child(name) else this.containerFqName,
this.typeParameters.child(nameResolver, typeParameterList)
this.typeParameters.child(nameResolver, typeParameterList),
typeTable
)
}
internal fun ClsStubBuilderContext.child(nameResolver: NameResolver): ClsStubBuilderContext {
internal fun ClsStubBuilderContext.child(nameResolver: NameResolver, typeTable: TypeTable): ClsStubBuilderContext {
return ClsStubBuilderContext(
this.components,
nameResolver,
this.containerFqName,
this.typeParameters
this.typeParameters,
typeTable
)
}
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.load.kotlin.header.isCompatibleMultifileClassKind
import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
public open class KotlinClsStubBuilder : ClsStubBuilder() {
@@ -77,18 +78,18 @@ public open class KotlinClsStubBuilder : ClsStubBuilder() {
return when {
header.isCompatiblePackageFacadeKind() -> {
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(annotationData, strings)
val context = components.createContext(nameResolver, packageFqName)
val context = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
createPackageFacadeStub(packageProto, packageFqName, context)
}
header.isCompatibleClassKind() -> {
if (header.isLocalClass) return null
val (nameResolver, classProto) = JvmProtoBufUtil.readClassDataFrom(annotationData, strings)
val context = components.createContext(nameResolver, packageFqName)
val context = components.createContext(nameResolver, packageFqName, TypeTable(classProto.typeTable))
createTopLevelClassStub(classId, classProto, context)
}
header.isCompatibleFileFacadeKind() -> {
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(annotationData, strings)
val context = components.createContext(nameResolver, packageFqName)
val context = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
createFileFacadeStub(packageProto, classId.asSingleFqName(), context)
}
else -> throw IllegalStateException("Should have processed " + file.getPath() + " with header $header")
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializedResourcePaths
import org.jetbrains.kotlin.serialization.js.toClassData
import org.jetbrains.kotlin.serialization.js.toPackageData
@@ -63,12 +64,14 @@ public open class KotlinJavaScriptStubBuilder : ClsStubBuilder() {
if (isPackageHeader) {
val packageData = content.toPackageData(nameResolver)
val context = components.createContext(packageData.nameResolver, packageFqName)
val context = components.createContext(
packageData.nameResolver, packageFqName, TypeTable(packageData.packageProto.typeTable)
)
return createPackageFacadeStub(packageData.packageProto, packageFqName, context)
}
else {
val classData = content.toClassData(nameResolver)
val context = components.createContext(classData.nameResolver, packageFqName)
val context = components.createContext(classData.nameResolver, packageFqName, TypeTable(classData.classProto.typeTable))
val classId = JsMetaFileUtils.getClassId(file)
return createTopLevelClassStub(classId, classData.classProto, context)
}
@@ -35,6 +35,9 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.Type
import org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection
import org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.Variance
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.type
import org.jetbrains.kotlin.serialization.deserialization.upperBounds
import org.jetbrains.kotlin.serialization.deserialization.varargElementType
import org.jetbrains.kotlin.types.DynamicTypeCapabilities
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.util.*
@@ -98,12 +101,12 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
}
val typeArgumentsListStub = KotlinPlaceHolderStubImpl<JetTypeArgumentList>(typeStub, JetStubElementTypes.TYPE_ARGUMENT_LIST)
typeArgumentProtoList.forEach { typeArgumentProto ->
val projectionKind = typeArgumentProto.getProjection().toProjectionKind()
val projectionKind = typeArgumentProto.projection.toProjectionKind()
val typeProjection = KotlinTypeProjectionStubImpl(typeArgumentsListStub, projectionKind.ordinal())
if (projectionKind != JetProjectionKind.STAR) {
val modifierKeywordToken = projectionKind.getToken() as? JetModifierKeywordToken
val modifierKeywordToken = projectionKind.token as? JetModifierKeywordToken
createModifierListStub(typeProjection, modifierKeywordToken.singletonOrEmptyList())
createTypeReferenceStub(typeProjection, typeArgumentProto.getType())
createTypeReferenceStub(typeProjection, typeArgumentProto.type(c.typeTable)!!)
}
}
}
@@ -116,12 +119,12 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
}
private fun createFunctionTypeStub(parent: StubElement<out PsiElement>, type: Type, isExtensionFunctionType: Boolean) {
val typeArgumentList = type.getArgumentList()
val typeArgumentList = type.argumentList
val functionType = KotlinPlaceHolderStubImpl<JetFunctionType>(parent, JetStubElementTypes.FUNCTION_TYPE)
if (isExtensionFunctionType) {
val functionTypeReceiverStub
= KotlinPlaceHolderStubImpl<JetFunctionTypeReceiver>(functionType, JetStubElementTypes.FUNCTION_TYPE_RECEIVER)
val receiverTypeProto = typeArgumentList.first().getType()
val receiverTypeProto = typeArgumentList.first().type(c.typeTable)!!
createTypeReferenceStub(functionTypeReceiverStub, receiverTypeProto)
}
@@ -129,11 +132,13 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
val typeArgumentsWithoutReceiverAndReturnType
= typeArgumentList.subList(if (isExtensionFunctionType) 1 else 0, typeArgumentList.size() - 1)
typeArgumentsWithoutReceiverAndReturnType.forEach { argument ->
val parameter = KotlinParameterStubImpl(parameterList, fqName = null, name = null, isMutable = false, hasValOrVar = false, hasDefaultValue = false)
createTypeReferenceStub(parameter, argument.getType())
val parameter = KotlinParameterStubImpl(
parameterList, fqName = null, name = null, isMutable = false, hasValOrVar = false, hasDefaultValue = false
)
createTypeReferenceStub(parameter, argument.type(c.typeTable)!!)
}
val returnType = typeArgumentList.last().getType()
val returnType = typeArgumentList.last().type(c.typeTable)!!
createTypeReferenceStub(functionType, returnType)
}
@@ -154,8 +159,10 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
hasValOrVar = false,
isMutable = false
)
val isVararg = valueParameterProto.hasVarargElementType()
val modifierList = if (isVararg) createModifierListStub(parameterStub, listOf(JetTokens.VARARG_KEYWORD)) else null
val varargElementType = valueParameterProto.varargElementType(c.typeTable)
val typeProto = varargElementType ?: valueParameterProto.type(c.typeTable)
val modifierList =
if (varargElementType != null) createModifierListStub(parameterStub, listOf(JetTokens.VARARG_KEYWORD)) else null
val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations(
container, callableProto, callableProto.annotatedCallableKind, index, valueParameterProto
)
@@ -163,7 +170,6 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
createAnnotationStubs(parameterAnnotations, modifierList ?: createEmptyModifierList(parameterStub))
}
val typeProto = if (isVararg) valueParameterProto.varargElementType else valueParameterProto.type
createTypeReferenceStub(parameterStub, typeProto)
}
}
@@ -185,21 +191,21 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
val typeParameterListStub = KotlinPlaceHolderStubImpl<JetTypeParameterList>(parent, JetStubElementTypes.TYPE_PARAMETER_LIST)
val protosForTypeConstraintList = arrayListOf<Pair<Name, Type>>()
for (proto in typeParameterProtoList) {
val name = c.nameResolver.getName(proto.getName())
val name = c.nameResolver.getName(proto.name)
val typeParameterStub = KotlinTypeParameterStubImpl(
typeParameterListStub,
name = name.ref(),
isInVariance = proto.getVariance() == Variance.IN,
isOutVariance = proto.getVariance() == Variance.OUT
isInVariance = proto.variance == Variance.IN,
isOutVariance = proto.variance == Variance.OUT
)
createTypeParameterModifierListStub(typeParameterStub, proto)
val upperBoundProtos = proto.getUpperBoundList()
val upperBoundProtos = proto.upperBounds(c.typeTable)
if (upperBoundProtos.isNotEmpty()) {
val upperBound = upperBoundProtos.first()
if (!upperBound.isDefaultUpperBound()) {
createTypeReferenceStub(typeParameterStub, upperBound)
}
protosForTypeConstraintList addAll upperBoundProtos.drop(1).map { Pair(name, it) }
protosForTypeConstraintList.addAll(upperBoundProtos.drop(1).map { Pair(name, it) })
}
}
return protosForTypeConstraintList
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
fun createTopLevelClassStub(classId: ClassId, classProto: ProtoBuf.Class, context: ClsStubBuilderContext): KotlinFileStubImpl {
@@ -51,7 +52,7 @@ fun createPackageFacadeStub(
): KotlinFileStubImpl {
val fileStub = KotlinFileStubForIde.forFile(packageFqName, packageFqName.isRoot)
setupFileStub(fileStub, packageFqName)
createCallableStubs(fileStub, c, ProtoContainer(null, packageFqName, c.nameResolver),
createCallableStubs(fileStub, c, ProtoContainer(null, packageFqName, c.nameResolver, c.typeTable),
packageProto.functionList, packageProto.propertyList)
return fileStub
}
@@ -64,7 +65,7 @@ fun createFileFacadeStub(
val packageFqName = facadeFqName.parent()
val fileStub = KotlinFileStubForIde.forFileFacadeStub(facadeFqName, packageFqName.isRoot)
setupFileStub(fileStub, packageFqName)
createCallableStubs(fileStub, c, ProtoContainer(null, packageFqName, c.nameResolver),
createCallableStubs(fileStub, c, ProtoContainer(null, packageFqName, c.nameResolver, c.typeTable),
packageProto.functionList, packageProto.propertyList)
return fileStub
}
@@ -82,8 +83,8 @@ fun createMultifileClassStub(
for (partFile in partFiles) {
val partHeader = partFile.classHeader
val (nameResolver, packageProto) = JvmProtoBufUtil.readPackageDataFrom(partHeader.annotationData!!, partHeader.strings!!)
val partContext = components.createContext(nameResolver, packageFqName)
createCallableStubs(fileStub, partContext, ProtoContainer(null, packageFqName, partContext.nameResolver),
val partContext = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
createCallableStubs(fileStub, partContext, ProtoContainer(null, packageFqName, partContext.nameResolver, partContext.typeTable),
packageProto.functionList, packageProto.propertyList)
}
return fileStub
@@ -39,11 +39,17 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsPackageProperty(old, new)) return false
if (old.hasTypeTable() != new.hasTypeTable()) return false
if (old.hasTypeTable()) {
if (!checkEquals(old.typeTable, new.typeTable)) return false
}
return true
}
public enum class ProtoBufPackageKind {
FUNCTION_LIST,
PROPERTY_LIST
PROPERTY_LIST,
TYPE_TABLE
}
public fun difference(old: ProtoBuf.Package, new: ProtoBuf.Package): EnumSet<ProtoBufPackageKind> {
@@ -53,6 +59,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsPackageProperty(old, new)) result.add(ProtoBufPackageKind.PROPERTY_LIST)
if (old.hasTypeTable() != new.hasTypeTable()) result.add(ProtoBufPackageKind.TYPE_TABLE)
if (old.hasTypeTable()) {
if (!checkEquals(old.typeTable, new.typeTable)) result.add(ProtoBufPackageKind.TYPE_TABLE)
}
return result
}
@@ -73,6 +84,8 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsClassSupertype(old, new)) return false
if (!checkEqualsClassSupertypeId(old, new)) return false
if (!checkEqualsClassNestedClassName(old, new)) return false
if (!checkEqualsClassConstructor(old, new)) return false
@@ -83,6 +96,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsClassEnumEntry(old, new)) return false
if (old.hasTypeTable() != new.hasTypeTable()) return false
if (old.hasTypeTable()) {
if (!checkEquals(old.typeTable, new.typeTable)) return false
}
if (old.getExtensionCount(JvmProtoBuf.classAnnotation) != new.getExtensionCount(JvmProtoBuf.classAnnotation)) return false
for(i in 0..old.getExtensionCount(JvmProtoBuf.classAnnotation) - 1) {
@@ -97,11 +115,13 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
COMPANION_OBJECT_NAME,
TYPE_PARAMETER_LIST,
SUPERTYPE_LIST,
SUPERTYPE_ID_LIST,
NESTED_CLASS_NAME_LIST,
CONSTRUCTOR_LIST,
FUNCTION_LIST,
PROPERTY_LIST,
ENUM_ENTRY_LIST,
TYPE_TABLE,
CLASS_ANNOTATION_LIST
}
@@ -124,6 +144,8 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsClassSupertype(old, new)) result.add(ProtoBufClassKind.SUPERTYPE_LIST)
if (!checkEqualsClassSupertypeId(old, new)) result.add(ProtoBufClassKind.SUPERTYPE_ID_LIST)
if (!checkEqualsClassNestedClassName(old, new)) result.add(ProtoBufClassKind.NESTED_CLASS_NAME_LIST)
if (!checkEqualsClassConstructor(old, new)) result.add(ProtoBufClassKind.CONSTRUCTOR_LIST)
@@ -134,6 +156,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsClassEnumEntry(old, new)) result.add(ProtoBufClassKind.ENUM_ENTRY_LIST)
if (old.hasTypeTable() != new.hasTypeTable()) result.add(ProtoBufClassKind.TYPE_TABLE)
if (old.hasTypeTable()) {
if (!checkEquals(old.typeTable, new.typeTable)) result.add(ProtoBufClassKind.TYPE_TABLE)
}
if (old.getExtensionCount(JvmProtoBuf.classAnnotation) != new.getExtensionCount(JvmProtoBuf.classAnnotation)) result.add(ProtoBufClassKind.CLASS_ANNOTATION_LIST)
for(i in 0..old.getExtensionCount(JvmProtoBuf.classAnnotation) - 1) {
@@ -151,7 +178,15 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkStringEquals(old.name, new.name)) return false
if (!checkEquals(old.returnType, new.returnType)) return false
if (old.hasReturnType() != new.hasReturnType()) return false
if (old.hasReturnType()) {
if (!checkEquals(old.returnType, new.returnType)) return false
}
if (old.hasReturnTypeId() != new.hasReturnTypeId()) return false
if (old.hasReturnTypeId()) {
if (old.returnTypeId != new.returnTypeId) return false
}
if (!checkEqualsFunctionTypeParameter(old, new)) return false
@@ -160,8 +195,18 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEquals(old.receiverType, new.receiverType)) return false
}
if (old.hasReceiverTypeId() != new.hasReceiverTypeId()) return false
if (old.hasReceiverTypeId()) {
if (old.receiverTypeId != new.receiverTypeId) return false
}
if (!checkEqualsFunctionValueParameter(old, new)) return false
if (old.hasTypeTable() != new.hasTypeTable()) return false
if (old.hasTypeTable()) {
if (!checkEquals(old.typeTable, new.typeTable)) return false
}
if (old.hasExtension(JvmProtoBuf.methodSignature) != new.hasExtension(JvmProtoBuf.methodSignature)) return false
if (old.hasExtension(JvmProtoBuf.methodSignature)) {
if (!checkEquals(old.getExtension(JvmProtoBuf.methodSignature), new.getExtension(JvmProtoBuf.methodSignature))) return false
@@ -183,7 +228,15 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkStringEquals(old.name, new.name)) return false
if (!checkEquals(old.returnType, new.returnType)) return false
if (old.hasReturnType() != new.hasReturnType()) return false
if (old.hasReturnType()) {
if (!checkEquals(old.returnType, new.returnType)) return false
}
if (old.hasReturnTypeId() != new.hasReturnTypeId()) return false
if (old.hasReturnTypeId()) {
if (old.returnTypeId != new.returnTypeId) return false
}
if (!checkEqualsPropertyTypeParameter(old, new)) return false
@@ -192,6 +245,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEquals(old.receiverType, new.receiverType)) return false
}
if (old.hasReceiverTypeId() != new.hasReceiverTypeId()) return false
if (old.hasReceiverTypeId()) {
if (old.receiverTypeId != new.receiverTypeId) return false
}
if (old.hasSetterValueParameter() != new.hasSetterValueParameter()) return false
if (old.hasSetterValueParameter()) {
if (!checkEquals(old.setterValueParameter, new.setterValueParameter)) return false
@@ -220,6 +278,17 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
return true
}
open fun checkEquals(old: ProtoBuf.TypeTable, new: ProtoBuf.TypeTable): Boolean {
if (!checkEqualsTypeTableType(old, new)) return false
if (old.hasFirstNullable() != new.hasFirstNullable()) return false
if (old.hasFirstNullable()) {
if (old.firstNullable != new.firstNullable) return false
}
return true
}
open fun checkEquals(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
if (old.id != new.id) return false
@@ -237,6 +306,8 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEqualsTypeParameterUpperBound(old, new)) return false
if (!checkEqualsTypeParameterUpperBoundId(old, new)) return false
return true
}
@@ -258,6 +329,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEquals(old.flexibleUpperBound, new.flexibleUpperBound)) return false
}
if (old.hasFlexibleUpperBoundId() != new.hasFlexibleUpperBoundId()) return false
if (old.hasFlexibleUpperBoundId()) {
if (old.flexibleUpperBoundId != new.flexibleUpperBoundId) return false
}
if (old.hasClassName() != new.hasClassName()) return false
if (old.hasClassName()) {
if (!checkClassIdEquals(old.className, new.className)) return false
@@ -314,13 +390,26 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkStringEquals(old.name, new.name)) return false
if (!checkEquals(old.type, new.type)) return false
if (old.hasType() != new.hasType()) return false
if (old.hasType()) {
if (!checkEquals(old.type, new.type)) return false
}
if (old.hasTypeId() != new.hasTypeId()) return false
if (old.hasTypeId()) {
if (old.typeId != new.typeId) return false
}
if (old.hasVarargElementType() != new.hasVarargElementType()) return false
if (old.hasVarargElementType()) {
if (!checkEquals(old.varargElementType, new.varargElementType)) return false
}
if (old.hasVarargElementTypeId() != new.hasVarargElementTypeId()) return false
if (old.hasVarargElementTypeId()) {
if (old.varargElementTypeId != new.varargElementTypeId) return false
}
if (old.hasExtension(JvmProtoBuf.index) != new.hasExtension(JvmProtoBuf.index)) return false
if (old.hasExtension(JvmProtoBuf.index)) {
if (old.getExtension(JvmProtoBuf.index) != new.getExtension(JvmProtoBuf.index)) return false
@@ -378,6 +467,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEquals(old.type, new.type)) return false
}
if (old.hasTypeId() != new.hasTypeId()) return false
if (old.hasTypeId()) {
if (old.typeId != new.typeId) return false
}
return true
}
@@ -494,6 +588,16 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
return true
}
open fun checkEqualsClassSupertypeId(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
if (old.supertypeIdCount != new.supertypeIdCount) return false
for(i in 0..old.supertypeIdCount - 1) {
if (old.getSupertypeId(i) != new.getSupertypeId(i)) return false
}
return true
}
open fun checkEqualsClassNestedClassName(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
if (old.nestedClassNameCount != new.nestedClassNameCount) return false
@@ -574,6 +678,16 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
return true
}
open fun checkEqualsTypeTableType(old: ProtoBuf.TypeTable, new: ProtoBuf.TypeTable): Boolean {
if (old.typeCount != new.typeCount) return false
for(i in 0..old.typeCount - 1) {
if (!checkEquals(old.getType(i), new.getType(i))) return false
}
return true
}
open fun checkEqualsTypeParameterUpperBound(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
if (old.upperBoundCount != new.upperBoundCount) return false
@@ -584,6 +698,16 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
return true
}
open fun checkEqualsTypeParameterUpperBoundId(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
if (old.upperBoundIdCount != new.upperBoundIdCount) return false
for(i in 0..old.upperBoundIdCount - 1) {
if (old.getUpperBoundId(i) != new.getUpperBoundId(i)) return false
}
return true
}
open fun checkEqualsTypeArgument(old: ProtoBuf.Type, new: ProtoBuf.Type): Boolean {
if (old.argumentCount != new.argumentCount) return false
@@ -666,6 +790,10 @@ public fun ProtoBuf.Package.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes:
hashCode = 31 * hashCode + getProperty(i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasTypeTable()) {
hashCode = 31 * hashCode + typeTable.hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -690,6 +818,10 @@ public fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (
hashCode = 31 * hashCode + getSupertype(i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..supertypeIdCount - 1) {
hashCode = 31 * hashCode + getSupertypeId(i)
}
for(i in 0..nestedClassNameCount - 1) {
hashCode = 31 * hashCode + stringIndexes(getNestedClassName(i))
}
@@ -710,6 +842,10 @@ public fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (
hashCode = 31 * hashCode + stringIndexes(getEnumEntry(i))
}
if (hasTypeTable()) {
hashCode = 31 * hashCode + typeTable.hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..getExtensionCount(JvmProtoBuf.classAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(JvmProtoBuf.classAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
}
@@ -726,7 +862,13 @@ public fun ProtoBuf.Function.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes
hashCode = 31 * hashCode + stringIndexes(name)
hashCode = 31 * hashCode + returnType.hashCode(stringIndexes, fqNameIndexes)
if (hasReturnType()) {
hashCode = 31 * hashCode + returnType.hashCode(stringIndexes, fqNameIndexes)
}
if (hasReturnTypeId()) {
hashCode = 31 * hashCode + returnTypeId
}
for(i in 0..typeParameterCount - 1) {
hashCode = 31 * hashCode + getTypeParameter(i).hashCode(stringIndexes, fqNameIndexes)
@@ -736,10 +878,18 @@ public fun ProtoBuf.Function.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes
hashCode = 31 * hashCode + receiverType.hashCode(stringIndexes, fqNameIndexes)
}
if (hasReceiverTypeId()) {
hashCode = 31 * hashCode + receiverTypeId
}
for(i in 0..valueParameterCount - 1) {
hashCode = 31 * hashCode + getValueParameter(i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasTypeTable()) {
hashCode = 31 * hashCode + typeTable.hashCode(stringIndexes, fqNameIndexes)
}
if (hasExtension(JvmProtoBuf.methodSignature)) {
hashCode = 31 * hashCode + getExtension(JvmProtoBuf.methodSignature).hashCode(stringIndexes, fqNameIndexes)
}
@@ -760,7 +910,13 @@ public fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes
hashCode = 31 * hashCode + stringIndexes(name)
hashCode = 31 * hashCode + returnType.hashCode(stringIndexes, fqNameIndexes)
if (hasReturnType()) {
hashCode = 31 * hashCode + returnType.hashCode(stringIndexes, fqNameIndexes)
}
if (hasReturnTypeId()) {
hashCode = 31 * hashCode + returnTypeId
}
for(i in 0..typeParameterCount - 1) {
hashCode = 31 * hashCode + getTypeParameter(i).hashCode(stringIndexes, fqNameIndexes)
@@ -770,6 +926,10 @@ public fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes
hashCode = 31 * hashCode + receiverType.hashCode(stringIndexes, fqNameIndexes)
}
if (hasReceiverTypeId()) {
hashCode = 31 * hashCode + receiverTypeId
}
if (hasSetterValueParameter()) {
hashCode = 31 * hashCode + setterValueParameter.hashCode(stringIndexes, fqNameIndexes)
}
@@ -793,6 +953,20 @@ public fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes
return hashCode
}
public fun ProtoBuf.TypeTable.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
var hashCode = 1
for(i in 0..typeCount - 1) {
hashCode = 31 * hashCode + getType(i).hashCode(stringIndexes, fqNameIndexes)
}
if (hasFirstNullable()) {
hashCode = 31 * hashCode + firstNullable
}
return hashCode
}
public fun ProtoBuf.TypeParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
var hashCode = 1
@@ -812,6 +986,10 @@ public fun ProtoBuf.TypeParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIn
hashCode = 31 * hashCode + getUpperBound(i).hashCode(stringIndexes, fqNameIndexes)
}
for(i in 0..upperBoundIdCount - 1) {
hashCode = 31 * hashCode + getUpperBoundId(i)
}
return hashCode
}
@@ -834,6 +1012,10 @@ public fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (I
hashCode = 31 * hashCode + flexibleUpperBound.hashCode(stringIndexes, fqNameIndexes)
}
if (hasFlexibleUpperBoundId()) {
hashCode = 31 * hashCode + flexibleUpperBoundId
}
if (hasClassName()) {
hashCode = 31 * hashCode + fqNameIndexes(className)
}
@@ -892,12 +1074,22 @@ public fun ProtoBuf.ValueParameter.hashCode(stringIndexes: (Int) -> Int, fqNameI
hashCode = 31 * hashCode + stringIndexes(name)
hashCode = 31 * hashCode + type.hashCode(stringIndexes, fqNameIndexes)
if (hasType()) {
hashCode = 31 * hashCode + type.hashCode(stringIndexes, fqNameIndexes)
}
if (hasTypeId()) {
hashCode = 31 * hashCode + typeId
}
if (hasVarargElementType()) {
hashCode = 31 * hashCode + varargElementType.hashCode(stringIndexes, fqNameIndexes)
}
if (hasVarargElementTypeId()) {
hashCode = 31 * hashCode + varargElementTypeId
}
if (hasExtension(JvmProtoBuf.index)) {
hashCode = 31 * hashCode + getExtension(JvmProtoBuf.index)
}
@@ -952,6 +1144,10 @@ public fun ProtoBuf.Type.Argument.hashCode(stringIndexes: (Int) -> Int, fqNameIn
hashCode = 31 * hashCode + type.hashCode(stringIndexes, fqNameIndexes)
}
if (hasTypeId()) {
hashCode = 31 * hashCode + typeId
}
return hashCode
}
@@ -210,6 +210,9 @@ private class DifferenceCalculatorForClass(oldData: ProtoMapValue, newData: Prot
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Class::getPropertyList))
ProtoBufClassKind.ENUM_ENTRY_LIST ->
names.addAll(calcDifferenceForNames(oldProto.enumEntryList, newProto.enumEntryList))
ProtoBufClassKind.TYPE_TABLE -> {
// TODO
}
ProtoBufClassKind.FLAGS,
ProtoBufClassKind.FQ_NAME,
ProtoBufClassKind.TYPE_PARAMETER_LIST,
@@ -257,6 +260,9 @@ private class DifferenceCalculatorForPackageFacade(oldData: ProtoMapValue, newDa
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Package::getFunctionList))
ProtoBufPackageKind.PROPERTY_LIST ->
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Package::getPropertyList))
ProtoBufPackageKind.TYPE_TABLE -> {
// TODO
}
else ->
throw IllegalArgumentException("Unsupported kind: $kind")
}