Serialize/deserialize annotations on type parameters

This commit is contained in:
Svetlana Isakova
2015-10-16 21:55:18 +03:00
parent b7e2604bf2
commit 25b40455ad
30 changed files with 397 additions and 131 deletions
+4
View File
@@ -50,3 +50,7 @@ extend ValueParameter {
extend Type {
repeated Annotation type_annotation = 150;
}
extend TypeParameter {
repeated Annotation type_parameter_annotation = 150;
}
@@ -148,6 +148,8 @@ message TypeParameter {
repeated Type upper_bound = 5;
repeated int32 upper_bound_id = 6;
extensions 100 to 999;
}
message Class {
@@ -6112,8 +6112,9 @@ public final class ProtoBuf {
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.Type)
}
public interface TypeParameterOrBuilder
extends com.google.protobuf.MessageLiteOrBuilder {
public interface TypeParameterOrBuilder extends
com.google.protobuf.GeneratedMessageLite.
ExtendableMessageOrBuilder<TypeParameter> {
// required int32 id = 1;
/**
@@ -6188,10 +6189,10 @@ public final class ProtoBuf {
* Protobuf type {@code org.jetbrains.kotlin.serialization.TypeParameter}
*/
public static final class TypeParameter extends
com.google.protobuf.GeneratedMessageLite
implements TypeParameterOrBuilder {
com.google.protobuf.GeneratedMessageLite.ExtendableMessage<
TypeParameter> implements TypeParameterOrBuilder {
// Use TypeParameter.newBuilder() to construct.
private TypeParameter(com.google.protobuf.GeneratedMessageLite.Builder builder) {
private TypeParameter(com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter, ?> builder) {
super(builder);
}
@@ -6528,6 +6529,10 @@ public final class ProtoBuf {
return false;
}
}
if (!extensionsAreInitialized()) {
memoizedIsInitialized = 0;
return false;
}
memoizedIsInitialized = 1;
return true;
}
@@ -6535,6 +6540,9 @@ public final class ProtoBuf {
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
com.google.protobuf.GeneratedMessageLite
.ExtendableMessage<org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter>.ExtensionWriter extensionWriter =
newExtensionWriter();
if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeInt32(1, id_);
}
@@ -6553,6 +6561,7 @@ public final class ProtoBuf {
for (int i = 0; i < upperBoundId_.size(); i++) {
output.writeInt32(6, upperBoundId_.get(i));
}
extensionWriter.writeUntil(1000, output);
}
private int memoizedSerializedSize = -1;
@@ -6590,6 +6599,7 @@ public final class ProtoBuf {
size += dataSize;
size += 1 * getUpperBoundIdList().size();
}
size += extensionsSerializedSize();
memoizedSerializedSize = size;
return size;
}
@@ -6665,9 +6675,8 @@ public final class ProtoBuf {
* Protobuf type {@code org.jetbrains.kotlin.serialization.TypeParameter}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageLite.Builder<
org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter, Builder>
implements org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameterOrBuilder {
com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<
org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter, Builder> implements org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameterOrBuilder {
// Construct using org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
@@ -6780,6 +6789,7 @@ public final class ProtoBuf {
}
}
this.mergeExtensionFields(other);
return this;
}
@@ -6798,6 +6808,10 @@ public final class ProtoBuf {
return false;
}
}
if (!extensionsAreInitialized()) {
return false;
}
return true;
}
@@ -15,6 +15,7 @@ public final class BuiltInsProtoBuf {
registry.add(org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf.compileTimeValue);
registry.add(org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf.parameterAnnotation);
registry.add(org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf.typeAnnotation);
registry.add(org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf.typeParameterAnnotation);
}
public static final int CLASS_NAME_FIELD_NUMBER = 150;
/**
@@ -136,6 +137,21 @@ public final class BuiltInsProtoBuf {
150,
com.google.protobuf.WireFormat.FieldType.MESSAGE,
false);
public static final int TYPE_PARAMETER_ANNOTATION_FIELD_NUMBER = 150;
/**
* <code>extend .org.jetbrains.kotlin.serialization.TypeParameter { ... }</code>
*/
public static final
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter,
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> typeParameterAnnotation = com.google.protobuf.GeneratedMessageLite
.newRepeatedGeneratedExtension(
org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.getDefaultInstance(),
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.getDefaultInstance(),
null,
150,
com.google.protobuf.WireFormat.FieldType.MESSAGE,
false);
static {
}
@@ -62,6 +62,12 @@ public interface AnnotationAndConstantLoader<A, C, T> {
@NotNull NameResolver nameResolver
);
@NotNull
List<A> loadTypeParameterAnnotations(
@NotNull ProtoBuf.TypeParameter typeParameter,
@NotNull NameResolver nameResolver
);
@Nullable
C loadPropertyConstant(
@NotNull ProtoContainer container,
@@ -14,52 +14,40 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.serialization.deserialization.descriptors;
package org.jetbrains.kotlin.serialization.deserialization.descriptors
import org.jetbrains.annotations.NotNull;
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.*;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.types.JetType
import java.util.*
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
class DeserializedTypeParameterDescriptor(
c: DeserializationContext, private val proto: ProtoBuf.TypeParameter, index: Int) : AbstractLazyTypeParameterDescriptor(c.storageManager, c.containingDeclaration, c.nameResolver.getName(proto.name), Deserialization.variance(proto.variance), proto.reified, index, SourceElement.NO_SOURCE) {
private val typeDeserializer: TypeDeserializer = c.typeDeserializer
private val typeTable: TypeTable = c.typeTable
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
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(),
c.getContainingDeclaration(),
c.getNameResolver().getName(proto.getName()),
Deserialization.variance(proto.getVariance()),
proto.getReified(),
index,
SourceElement.NO_SOURCE);
this.proto = proto;
this.typeDeserializer = c.getTypeDeserializer();
this.typeTable = c.getTypeTable();
private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
c.components.annotationAndConstantLoader
.loadTypeParameterAnnotations(proto, c.nameResolver)
.map { AnnotationWithTarget(it, null) }
}
@NotNull
@Override
protected Set<JetType> resolveUpperBounds() {
List<ProtoBuf.Type> upperBounds = ProtoTypeTableUtilKt.upperBounds(proto, typeTable);
override fun getAnnotations(): Annotations = annotations
override fun resolveUpperBounds(): Set<JetType> {
val upperBounds = proto.upperBounds(typeTable)
if (upperBounds.isEmpty()) {
return Collections.singleton(getBuiltIns(this).getDefaultBound());
return setOf(this.builtIns.getDefaultBound())
}
Set<JetType> result = new LinkedHashSet<JetType>(upperBounds.size());
for (ProtoBuf.Type upperBound : upperBounds) {
result.add(typeDeserializer.type(upperBound, Annotations.Companion.getEMPTY()));
val result = LinkedHashSet<JetType>(upperBounds.size())
for (upperBound in upperBounds) {
result.add(typeDeserializer.type(upperBound, Annotations.EMPTY))
}
return result;
return result
}
}