Improve code after conversion, fix some warnings
This commit is contained in:
+20
-32
@@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.CallableKind.*
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.TypeParameter
|
||||
import java.util.ArrayList
|
||||
|
||||
public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
private val components: DeserializationComponents get() = context.components
|
||||
@@ -62,7 +61,7 @@ public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
local.typeDeserializer.type(proto.getReturnType()),
|
||||
local.typeDeserializer.getOwnTypeParameters(),
|
||||
getDispatchReceiverParameter(),
|
||||
local.typeDeserializer.typeOrNull(if (proto.hasReceiverType()) proto.getReceiverType() else null)
|
||||
if (proto.hasReceiverType()) local.typeDeserializer.type(proto.getReceiverType()) else null
|
||||
)
|
||||
|
||||
val getter = if (Flags.HAS_GETTER.get(flags)) {
|
||||
@@ -104,7 +103,6 @@ public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
)
|
||||
val setterLocal = local.childContext(setter, listOf())
|
||||
val valueParameters = setterLocal.memberDeserializer.valueParameters(proto, AnnotatedCallableKind.PROPERTY_SETTER)
|
||||
assert(valueParameters.size() == 1) { "Property setter should have a single value parameter: $setter" }
|
||||
setter.initialize(valueParameters.single())
|
||||
setter
|
||||
}
|
||||
@@ -119,12 +117,8 @@ public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
if (Flags.HAS_CONSTANT.get(flags)) {
|
||||
property.setCompileTimeInitializer(
|
||||
components.storageManager.createNullableLazyValue {
|
||||
val containingDeclaration =
|
||||
context.containingDeclaration as? ClassOrPackageFragmentDescriptor
|
||||
?: error("Only members in classes or package fragments should be serialized: ${context.containingDeclaration}")
|
||||
components.constantLoader.loadPropertyConstant(
|
||||
containingDeclaration, proto, context.nameResolver, AnnotatedCallableKind.PROPERTY
|
||||
)
|
||||
val container = context.containingDeclaration.asClassOrPackage()
|
||||
components.constantLoader.loadPropertyConstant(container, proto, context.nameResolver, AnnotatedCallableKind.PROPERTY)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -139,7 +133,7 @@ public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
val function = DeserializedSimpleFunctionDescriptor.create(context.containingDeclaration, proto, context.nameResolver, annotations)
|
||||
val local = context.childContext(function, proto.getTypeParameterList())
|
||||
function.initialize(
|
||||
local.typeDeserializer.typeOrNull(if (proto.hasReceiverType()) proto.getReceiverType() else null),
|
||||
if (proto.hasReceiverType()) local.typeDeserializer.type(proto.getReceiverType()) else null,
|
||||
getDispatchReceiverParameter(),
|
||||
local.typeDeserializer.getOwnTypeParameters(),
|
||||
local.memberDeserializer.valueParameters(proto, AnnotatedCallableKind.FUNCTION),
|
||||
@@ -171,48 +165,38 @@ public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
}
|
||||
|
||||
private fun getAnnotations(proto: Callable, flags: Int, kind: AnnotatedCallableKind): Annotations {
|
||||
val containingDeclaration =
|
||||
context.containingDeclaration as? ClassOrPackageFragmentDescriptor
|
||||
?: error("Only members in classes or package fragments should be serialized: ${context.containingDeclaration}")
|
||||
return if (Flags.HAS_ANNOTATIONS.get(flags))
|
||||
components.annotationLoader.loadCallableAnnotations(containingDeclaration, proto, context.nameResolver, kind)
|
||||
components.annotationLoader.loadCallableAnnotations(
|
||||
context.containingDeclaration.asClassOrPackage(), proto, context.nameResolver, kind
|
||||
)
|
||||
else
|
||||
Annotations.EMPTY
|
||||
}
|
||||
|
||||
public fun typeParameters(protos: List<TypeParameter>): List<DeserializedTypeParameterDescriptor> {
|
||||
val result = ArrayList<DeserializedTypeParameterDescriptor>(protos.size())
|
||||
for (i in protos.indices) {
|
||||
val proto = protos.get(i)
|
||||
result.add(DeserializedTypeParameterDescriptor(
|
||||
return protos.withIndices().map { val (i, proto) = it
|
||||
DeserializedTypeParameterDescriptor(
|
||||
components.storageManager, context.typeDeserializer, proto, context.containingDeclaration,
|
||||
context.nameResolver.getName(proto.getName()),
|
||||
variance(proto.getVariance()), proto.getReified(), i
|
||||
))
|
||||
)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
|
||||
val classOrPackage =
|
||||
context.containingDeclaration.getContainingDeclaration() as? ClassOrPackageFragmentDescriptor
|
||||
?: error("Only members in classes or package fragments should be serialized: ${context.containingDeclaration}")
|
||||
val containerOfCallable = context.containingDeclaration.getContainingDeclaration().asClassOrPackage()
|
||||
|
||||
val protos = callable.getValueParameterList()
|
||||
val result = ArrayList<ValueParameterDescriptor>(protos.size())
|
||||
for (i in protos.indices) {
|
||||
val proto = protos.get(i)
|
||||
result.add(ValueParameterDescriptorImpl(
|
||||
return callable.getValueParameterList().withIndices().map { val (i, proto) = it
|
||||
ValueParameterDescriptorImpl(
|
||||
context.containingDeclaration, null, i,
|
||||
getParameterAnnotations(classOrPackage, callable, kind, proto),
|
||||
getParameterAnnotations(containerOfCallable, callable, kind, proto),
|
||||
context.nameResolver.getName(proto.getName()),
|
||||
context.typeDeserializer.type(proto.getType()),
|
||||
Flags.DECLARES_DEFAULT_VALUE.get(proto.getFlags()),
|
||||
context.typeDeserializer.typeOrNull(if (proto.hasVarargElementType()) proto.getVarargElementType() else null),
|
||||
if (proto.hasVarargElementType()) context.typeDeserializer.type(proto.getVarargElementType()) else null,
|
||||
SourceElement.NO_SOURCE
|
||||
))
|
||||
)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getParameterAnnotations(
|
||||
@@ -226,4 +210,8 @@ public class MemberDeserializer(private val context: DeserializationContext) {
|
||||
else
|
||||
Annotations.EMPTY
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.asClassOrPackage(): ClassOrPackageFragmentDescriptor =
|
||||
this as? ClassOrPackageFragmentDescriptor
|
||||
?: error("Only members in classes or package fragments should be serialized: $this")
|
||||
}
|
||||
|
||||
+6
-9
@@ -76,14 +76,6 @@ public class TypeDeserializer {
|
||||
return UtilsPackage.toReadOnlyList(typeParameterDescriptors.values());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetType typeOrNull(@Nullable ProtoBuf.Type proto) {
|
||||
if (proto == null) {
|
||||
return null;
|
||||
}
|
||||
return type(proto);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType type(@NotNull ProtoBuf.Type proto) {
|
||||
if (proto.hasFlexibleTypeCapabilitiesId()) {
|
||||
@@ -169,7 +161,12 @@ public class TypeDeserializer {
|
||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) descriptor;
|
||||
return typeParameterDescriptor.getDefaultType().getMemberScope();
|
||||
}
|
||||
return ((ClassDescriptor) descriptor).getMemberScope(typeArguments);
|
||||
else if (descriptor instanceof ClassDescriptor) {
|
||||
return ((ClassDescriptor) descriptor).getMemberScope(typeArguments);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unsupported classifier: " + descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-8
@@ -17,10 +17,9 @@
|
||||
package org.jetbrains.jet.descriptors.serialization.context
|
||||
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationLoader
|
||||
import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.descriptors.serialization.*
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf.TypeParameter
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationLoader
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.ConstantLoader
|
||||
import org.jetbrains.jet.lang.resolve.name.ClassId
|
||||
|
||||
@@ -53,14 +52,10 @@ public class DeserializationContext(
|
||||
|
||||
val memberDeserializer: MemberDeserializer = MemberDeserializer(this)
|
||||
|
||||
// Not using default arguments here because Java code calls this function
|
||||
fun childContext(descriptor: DeclarationDescriptor, typeParameterProtos: List<TypeParameter>): DeserializationContext =
|
||||
childContext(descriptor, typeParameterProtos, this.nameResolver)
|
||||
|
||||
fun childContext(
|
||||
descriptor: DeclarationDescriptor,
|
||||
typeParameterProtos: List<TypeParameter>,
|
||||
nameResolver: NameResolver
|
||||
typeParameterProtos: List<ProtoBuf.TypeParameter>,
|
||||
nameResolver: NameResolver = this.nameResolver
|
||||
): DeserializationContext {
|
||||
val child = DeserializationContext(components, nameResolver, descriptor, parentTypeDeserializer = this.typeDeserializer)
|
||||
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ public class DeserializedClassDescriptor(
|
||||
private fun computeSuperTypes(): Collection<JetType> {
|
||||
val supertypes = ArrayList<JetType>(classProto.getSupertypeCount())
|
||||
for (supertype in classProto.getSupertypeList()) {
|
||||
supertypes.add(context.typeDeserializer.`type`(supertype))
|
||||
supertypes.add(context.typeDeserializer.type(supertype))
|
||||
}
|
||||
return supertypes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user