Serialize/deserialize annotations on types

This commit is contained in:
Alexander Udalov
2015-04-09 21:12:08 +03:00
parent 88abcdbde5
commit 0732b78853
25 changed files with 420 additions and 128 deletions
@@ -21,9 +21,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.load.kotlin.SignatureDeserializer; import org.jetbrains.kotlin.load.kotlin.SignatureDeserializer;
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.serialization.AnnotationSerializer;
import org.jetbrains.kotlin.serialization.ProtoBuf; import org.jetbrains.kotlin.serialization.ProtoBuf;
import org.jetbrains.kotlin.serialization.SerializerExtension; import org.jetbrains.kotlin.serialization.SerializerExtension;
import org.jetbrains.kotlin.serialization.StringTable; import org.jetbrains.kotlin.serialization.StringTable;
@@ -31,6 +33,7 @@ import org.jetbrains.kotlin.serialization.deserialization.NameResolver;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor; import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor; import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor;
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf; import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method; import org.jetbrains.org.objectweb.asm.commons.Method;
@@ -70,6 +73,14 @@ public class JvmSerializerExtension extends SerializerExtension {
} }
} }
@Override
public void serializeType(@NotNull JetType type, @NotNull ProtoBuf.Type.Builder proto, @NotNull StringTable stringTable) {
// TODO: don't store type annotations in our binary metadata on Java 8, use *TypeAnnotations attributes instead
for (AnnotationDescriptor annotation : type.getAnnotations()) {
proto.addExtension(JvmProtoBuf.typeAnnotation, AnnotationSerializer.INSTANCE$.serializeAnnotation(annotation, stringTable));
}
}
@Override @Override
@NotNull @NotNull
public String getLocalClassName(@NotNull ClassDescriptor descriptor) { public String getLocalClassName(@NotNull ClassDescriptor descriptor) {
@@ -299,7 +299,7 @@ public class DescriptorSerializer {
case IN_VARIANCE: case IN_VARIANCE:
return ProtoBuf.TypeParameter.Variance.IN; return ProtoBuf.TypeParameter.Variance.IN;
case OUT_VARIANCE: case OUT_VARIANCE:
return ProtoBuf.TypeParameter.Variance.OUT; return ProtoBuf.TypeParameter.Variance.OUT;
} }
throw new IllegalStateException("Unknown variance: " + variance); throw new IllegalStateException("Unknown variance: " + variance);
} }
@@ -323,6 +323,8 @@ public class DescriptorSerializer {
builder.setNullable(true); builder.setNullable(true);
} }
extension.serializeType(type, builder, stringTable);
return builder; return builder;
} }
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor; import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor; import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
import org.jetbrains.kotlin.types.JetType;
import java.util.Collection; import java.util.Collection;
@@ -53,6 +54,13 @@ public abstract class SerializerExtension {
) { ) {
} }
public void serializeType(
@NotNull JetType type,
@NotNull ProtoBuf.Type.Builder proto,
@NotNull StringTable stringTable
) {
}
@NotNull @NotNull
public String getLocalClassName(@NotNull ClassDescriptor descriptor) { public String getLocalClassName(@NotNull ClassDescriptor descriptor) {
throw new UnsupportedOperationException("Local classes are unsupported: " + descriptor); throw new UnsupportedOperationException("Local classes are unsupported: " + descriptor);
@@ -0,0 +1,5 @@
package test
annotation class A
fun ([A] String).foo() {}
@@ -0,0 +1,7 @@
package test
internal fun [test.A()] kotlin.String.foo(): kotlin.Unit
internal final annotation class A : kotlin.Annotation {
/*primary*/ public constructor A()
}
@@ -0,0 +1,7 @@
package test
annotation class A
class SimpleTypeAnnotation {
fun foo(x: [A] IntRange): [A] Int = 42
}
@@ -0,0 +1,10 @@
package test
internal final annotation class A : kotlin.Annotation {
/*primary*/ public constructor A()
}
internal final class SimpleTypeAnnotation {
/*primary*/ public constructor SimpleTypeAnnotation()
internal final fun foo(/*0*/ x: [test.A()] kotlin.IntRange): [test.A()] kotlin.Int
}
@@ -0,0 +1,9 @@
// ALLOW_AST_ACCESS
package test
annotation class Ann(val x: String, val y: Double)
class TypeAnnotationWithArguments {
fun foo(param: [Ann("param", 3.14)] IntRange): [Ann("fun", 2.72)] Unit {}
}
@@ -0,0 +1,14 @@
package test
internal final annotation class Ann : kotlin.Annotation {
/*primary*/ public constructor Ann(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Double)
internal final val x: kotlin.String
internal final fun <get-x>(): kotlin.String
internal final val y: kotlin.Double
internal final fun <get-y>(): kotlin.Double
}
internal final class TypeAnnotationWithArguments {
/*primary*/ public constructor TypeAnnotationWithArguments()
internal final fun foo(/*0*/ param: [test.Ann(x = "param": kotlin.String, y = 3.14.toDouble(): kotlin.Double)] kotlin.IntRange): [test.Ann(x = "fun": kotlin.String, y = 2.72.toDouble(): kotlin.Double)] kotlin.Unit
}
@@ -2262,6 +2262,33 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledKotlin(fileName); doTestCompiledKotlin(fileName);
} }
} }
@TestMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Types extends AbstractLoadJavaTest {
public void testAllFilesPresentInTypes() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/types"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ReceiverParameter.kt")
public void testReceiverParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("SimpleTypeAnnotation.kt")
public void testSimpleTypeAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("TypeAnnotationWithArguments.kt")
public void testTypeAnnotationWithArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt");
doTestCompiledKotlin(fileName);
}
}
} }
@TestMetadata("compiler/testData/loadJava/compiledKotlin/class") @TestMetadata("compiler/testData/loadJava/compiledKotlin/class")
@@ -419,6 +419,33 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
doTest(fileName); doTest(fileName);
} }
} }
@TestMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Types extends AbstractJvmRuntimeDescriptorLoaderTest {
public void testAllFilesPresentInTypes() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/types"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ReceiverParameter.kt")
public void testReceiverParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
doTest(fileName);
}
@TestMetadata("SimpleTypeAnnotation.kt")
public void testSimpleTypeAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt");
doTest(fileName);
}
@TestMetadata("TypeAnnotationWithArguments.kt")
public void testTypeAnnotationWithArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt");
doTest(fileName);
}
}
} }
@TestMetadata("compiler/testData/loadJava/compiledKotlin/class") @TestMetadata("compiler/testData/loadJava/compiledKotlin/class")
@@ -5362,8 +5362,9 @@ public final class DebugProtoBuf {
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.Annotation) // @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.Annotation)
} }
public interface TypeOrBuilder public interface TypeOrBuilder extends
extends com.google.protobuf.MessageOrBuilder { com.google.protobuf.GeneratedMessage.
ExtendableMessageOrBuilder<Type> {
// required .org.jetbrains.kotlin.serialization.Type.Constructor constructor = 1; // required .org.jetbrains.kotlin.serialization.Type.Constructor constructor = 1;
/** /**
@@ -5421,7 +5422,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
boolean hasFlexibleTypeCapabilitiesId(); boolean hasFlexibleTypeCapabilitiesId();
@@ -5431,7 +5432,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
int getFlexibleTypeCapabilitiesId(); int getFlexibleTypeCapabilitiesId();
@@ -5472,10 +5473,10 @@ public final class DebugProtoBuf {
* Protobuf type {@code org.jetbrains.kotlin.serialization.Type} * Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
*/ */
public static final class Type extends public static final class Type extends
com.google.protobuf.GeneratedMessage com.google.protobuf.GeneratedMessage.ExtendableMessage<
implements TypeOrBuilder { Type> implements TypeOrBuilder {
// Use Type.newBuilder() to construct. // Use Type.newBuilder() to construct.
private Type(com.google.protobuf.GeneratedMessage.Builder<?> builder) { private Type(com.google.protobuf.GeneratedMessage.ExtendableBuilder<org.jetbrains.kotlin.serialization.DebugProtoBuf.Type, ?> builder) {
super(builder); super(builder);
this.unknownFields = builder.getUnknownFields(); this.unknownFields = builder.getUnknownFields();
} }
@@ -7066,7 +7067,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public boolean hasFlexibleTypeCapabilitiesId() { public boolean hasFlexibleTypeCapabilitiesId() {
@@ -7078,7 +7079,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public int getFlexibleTypeCapabilitiesId() { public int getFlexibleTypeCapabilitiesId() {
@@ -7157,6 +7158,10 @@ public final class DebugProtoBuf {
return false; return false;
} }
} }
if (!extensionsAreInitialized()) {
memoizedIsInitialized = 0;
return false;
}
memoizedIsInitialized = 1; memoizedIsInitialized = 1;
return true; return true;
} }
@@ -7164,6 +7169,9 @@ public final class DebugProtoBuf {
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
getSerializedSize(); getSerializedSize();
com.google.protobuf.GeneratedMessage
.ExtendableMessage<org.jetbrains.kotlin.serialization.DebugProtoBuf.Type>.ExtensionWriter extensionWriter =
newExtensionWriter();
if (((bitField0_ & 0x00000001) == 0x00000001)) { if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeMessage(1, constructor_); output.writeMessage(1, constructor_);
} }
@@ -7179,6 +7187,7 @@ public final class DebugProtoBuf {
if (((bitField0_ & 0x00000008) == 0x00000008)) { if (((bitField0_ & 0x00000008) == 0x00000008)) {
output.writeMessage(5, flexibleUpperBound_); output.writeMessage(5, flexibleUpperBound_);
} }
extensionWriter.writeUntil(200, output);
getUnknownFields().writeTo(output); getUnknownFields().writeTo(output);
} }
@@ -7208,6 +7217,7 @@ public final class DebugProtoBuf {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
.computeMessageSize(5, flexibleUpperBound_); .computeMessageSize(5, flexibleUpperBound_);
} }
size += extensionsSerializedSize();
size += getUnknownFields().getSerializedSize(); size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size; memoizedSerializedSize = size;
return size; return size;
@@ -7290,8 +7300,8 @@ public final class DebugProtoBuf {
* Protobuf type {@code org.jetbrains.kotlin.serialization.Type} * Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
*/ */
public static final class Builder extends public static final class Builder extends
com.google.protobuf.GeneratedMessage.Builder<Builder> com.google.protobuf.GeneratedMessage.ExtendableBuilder<
implements org.jetbrains.kotlin.serialization.DebugProtoBuf.TypeOrBuilder { org.jetbrains.kotlin.serialization.DebugProtoBuf.Type, Builder> implements org.jetbrains.kotlin.serialization.DebugProtoBuf.TypeOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() { getDescriptor() {
return org.jetbrains.kotlin.serialization.DebugProtoBuf.internal_static_org_jetbrains_kotlin_serialization_Type_descriptor; return org.jetbrains.kotlin.serialization.DebugProtoBuf.internal_static_org_jetbrains_kotlin_serialization_Type_descriptor;
@@ -7464,6 +7474,7 @@ public final class DebugProtoBuf {
if (other.hasFlexibleUpperBound()) { if (other.hasFlexibleUpperBound()) {
mergeFlexibleUpperBound(other.getFlexibleUpperBound()); mergeFlexibleUpperBound(other.getFlexibleUpperBound());
} }
this.mergeExtensionFields(other);
this.mergeUnknownFields(other.getUnknownFields()); this.mergeUnknownFields(other.getUnknownFields());
return this; return this;
} }
@@ -7489,6 +7500,10 @@ public final class DebugProtoBuf {
return false; return false;
} }
} }
if (!extensionsAreInitialized()) {
return false;
}
return true; return true;
} }
@@ -7909,7 +7924,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public boolean hasFlexibleTypeCapabilitiesId() { public boolean hasFlexibleTypeCapabilitiesId() {
@@ -7921,7 +7936,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public int getFlexibleTypeCapabilitiesId() { public int getFlexibleTypeCapabilitiesId() {
@@ -7933,7 +7948,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public Builder setFlexibleTypeCapabilitiesId(int value) { public Builder setFlexibleTypeCapabilitiesId(int value) {
@@ -7948,7 +7963,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public Builder clearFlexibleTypeCapabilitiesId() { public Builder clearFlexibleTypeCapabilitiesId() {
@@ -9885,6 +9900,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
boolean hasData(); boolean hasData();
@@ -9894,6 +9910,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable getData(); org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable getData();
@@ -9903,6 +9920,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
org.jetbrains.kotlin.serialization.DebugProtoBuf.CallableOrBuilder getDataOrBuilder(); org.jetbrains.kotlin.serialization.DebugProtoBuf.CallableOrBuilder getDataOrBuilder();
@@ -10020,6 +10038,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public boolean hasData() { public boolean hasData() {
@@ -10031,6 +10050,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable getData() { public org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable getData() {
@@ -10042,6 +10062,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.DebugProtoBuf.CallableOrBuilder getDataOrBuilder() { public org.jetbrains.kotlin.serialization.DebugProtoBuf.CallableOrBuilder getDataOrBuilder() {
@@ -10306,6 +10327,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public boolean hasData() { public boolean hasData() {
@@ -10317,6 +10339,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable getData() { public org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable getData() {
@@ -10332,6 +10355,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder setData(org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable value) { public Builder setData(org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable value) {
@@ -10353,6 +10377,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder setData( public Builder setData(
@@ -10372,6 +10397,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder mergeData(org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable value) { public Builder mergeData(org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable value) {
@@ -10396,6 +10422,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder clearData() { public Builder clearData() {
@@ -10414,6 +10441,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable.Builder getDataBuilder() { public org.jetbrains.kotlin.serialization.DebugProtoBuf.Callable.Builder getDataBuilder() {
@@ -10427,6 +10455,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.DebugProtoBuf.CallableOrBuilder getDataOrBuilder() { public org.jetbrains.kotlin.serialization.DebugProtoBuf.CallableOrBuilder getDataOrBuilder() {
@@ -10442,6 +10471,7 @@ public final class DebugProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
private com.google.protobuf.SingleFieldBuilder< private com.google.protobuf.SingleFieldBuilder<
@@ -17002,7 +17032,7 @@ public final class DebugProtoBuf {
"\n\004BYTE\020\000\022\010\n\004CHAR\020\001\022\t\n\005SHORT\020\002\022\007\n\003INT\020\003\022\010" + "\n\004BYTE\020\000\022\010\n\004CHAR\020\001\022\t\n\005SHORT\020\002\022\007\n\003INT\020\003\022\010" +
"\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE" + "\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE" +
"AN\020\007\022\n\n\006STRING\020\010\022\t\n\005CLASS\020\t\022\010\n\004ENUM\020\n\022\016\n" + "AN\020\007\022\n\n\006STRING\020\010\022\t\n\005CLASS\020\t\022\010\n\004ENUM\020\n\022\016\n" +
"\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\377\004\n\004Type\022I\n\013con", "\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\206\005\n\004Type\022I\n\013con",
"structor\030\001 \002(\01324.org.jetbrains.kotlin.se" + "structor\030\001 \002(\01324.org.jetbrains.kotlin.se" +
"rialization.Type.Constructor\022C\n\010argument" + "rialization.Type.Constructor\022C\n\010argument" +
"\030\002 \003(\01321.org.jetbrains.kotlin.serializat" + "\030\002 \003(\01321.org.jetbrains.kotlin.serializat" +
@@ -17018,55 +17048,55 @@ public final class DebugProtoBuf {
"ialization.Type.Argument.Projection:\003INV" + "ialization.Type.Argument.Projection:\003INV" +
"\0226\n\004type\030\002 \001(\0132(.org.jetbrains.kotlin.se" + "\0226\n\004type\030\002 \001(\0132(.org.jetbrains.kotlin.se" +
"rialization.Type\"0\n\nProjection\022\006\n\002IN\020\000\022\007" + "rialization.Type\"0\n\nProjection\022\006\n\002IN\020\000\022\007" +
"\n\003OUT\020\001\022\007\n\003INV\020\002\022\010\n\004STAR\020\003\"\371\001\n\rTypeParam" + "\n\003OUT\020\001\022\007\n\003INV\020\002\022\010\n\004STAR\020\003*\005\010d\020\310\001\"\371\001\n\rTy" +
"eter\022\n\n\002id\030\001 \002(\005\022\014\n\004name\030\002 \002(\005\022\026\n\007reifie" + "peParameter\022\n\n\002id\030\001 \002(\005\022\014\n\004name\030\002 \002(\005\022\026\n" +
"d\030\003 \001(\010:\005false\022Q\n\010variance\030\004 \001(\0162:.org.j" + "\007reified\030\003 \001(\010:\005false\022Q\n\010variance\030\004 \001(\0162" +
"etbrains.kotlin.serialization.TypeParame" + ":.org.jetbrains.kotlin.serialization.Typ" +
"ter.Variance:\003INV\022=\n\013upper_bound\030\005 \003(\0132(", "eParameter.Variance:\003INV\022=\n\013upper_bound\030",
".org.jetbrains.kotlin.serialization.Type" + "\005 \003(\0132(.org.jetbrains.kotlin.serializati" +
"\"$\n\010Variance\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\"\261" + "on.Type\"$\n\010Variance\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003" +
"\005\n\005Class\022\020\n\005flags\030\001 \001(\005:\0010\022\017\n\007fq_name\030\003 " + "INV\020\002\"\261\005\n\005Class\022\020\n\005flags\030\001 \001(\005:\0010\022\017\n\007fq_" +
"\002(\005\022\035\n\025companion_object_name\030\004 \001(\005\022I\n\016ty" + "name\030\003 \002(\005\022\035\n\025companion_object_name\030\004 \001(" +
"pe_parameter\030\005 \003(\01321.org.jetbrains.kotli" + "\005\022I\n\016type_parameter\030\005 \003(\01321.org.jetbrain" +
"n.serialization.TypeParameter\022;\n\tsuperty" + "s.kotlin.serialization.TypeParameter\022;\n\t" +
"pe\030\006 \003(\0132(.org.jetbrains.kotlin.serializ" + "supertype\030\006 \003(\0132(.org.jetbrains.kotlin.s" +
"ation.Type\022\031\n\021nested_class_name\030\007 \003(\005\022<\n" + "erialization.Type\022\031\n\021nested_class_name\030\007" +
"\006member\030\013 \003(\0132,.org.jetbrains.kotlin.ser" + " \003(\005\022<\n\006member\030\013 \003(\0132,.org.jetbrains.kot" +
"ialization.Callable\022\022\n\nenum_entry\030\014 \003(\005\022", "lin.serialization.Callable\022\022\n\nenum_entry",
"Y\n\023primary_constructor\030\r \001(\0132<.org.jetbr" + "\030\014 \003(\005\022Y\n\023primary_constructor\030\r \001(\0132<.or" +
"ains.kotlin.serialization.Class.PrimaryC" + "g.jetbrains.kotlin.serialization.Class.P" +
"onstructor\022K\n\025secondary_constructor\030\016 \003(" + "rimaryConstructor\022K\n\025secondary_construct" +
"\0132,.org.jetbrains.kotlin.serialization.C" + "or\030\016 \003(\0132,.org.jetbrains.kotlin.serializ" +
"allable\032P\n\022PrimaryConstructor\022:\n\004data\030\001 " + "ation.Callable\032P\n\022PrimaryConstructor\022:\n\004" +
"\001(\0132,.org.jetbrains.kotlin.serialization" + "data\030\001 \001(\0132,.org.jetbrains.kotlin.serial" +
".Callable\"p\n\004Kind\022\t\n\005CLASS\020\000\022\t\n\005TRAIT\020\001\022" + "ization.Callable\"p\n\004Kind\022\t\n\005CLASS\020\000\022\t\n\005T" +
"\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENTRY\020\003\022\024\n\020ANNOT" + "RAIT\020\001\022\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENTRY\020\003\022\024" +
"ATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\020\n\014CLASS_OBJEC" + "\n\020ANNOTATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\020\n\014CLAS" +
"T\020\006*\005\010d\020\310\001\"N\n\007Package\022<\n\006member\030\001 \003(\0132,.", "S_OBJECT\020\006*\005\010d\020\310\001\"N\n\007Package\022<\n\006member\030\001",
"org.jetbrains.kotlin.serialization.Calla" + " \003(\0132,.org.jetbrains.kotlin.serializatio" +
"ble*\005\010d\020\310\001\"\300\005\n\010Callable\022\r\n\005flags\030\001 \001(\005\022\024" + "n.Callable*\005\010d\020\310\001\"\300\005\n\010Callable\022\r\n\005flags\030" +
"\n\014getter_flags\030\t \001(\005\022\024\n\014setter_flags\030\n \001" + "\001 \001(\005\022\024\n\014getter_flags\030\t \001(\005\022\024\n\014setter_fl" +
"(\005\022I\n\016type_parameter\030\004 \003(\01321.org.jetbrai" + "ags\030\n \001(\005\022I\n\016type_parameter\030\004 \003(\01321.org." +
"ns.kotlin.serialization.TypeParameter\022?\n" + "jetbrains.kotlin.serialization.TypeParam" +
"\rreceiver_type\030\005 \001(\0132(.org.jetbrains.kot" + "eter\022?\n\rreceiver_type\030\005 \001(\0132(.org.jetbra" +
"lin.serialization.Type\022\014\n\004name\030\006 \002(\005\022T\n\017" + "ins.kotlin.serialization.Type\022\014\n\004name\030\006 " +
"value_parameter\030\007 \003(\0132;.org.jetbrains.ko" + "\002(\005\022T\n\017value_parameter\030\007 \003(\0132;.org.jetbr" +
"tlin.serialization.Callable.ValueParamet" + "ains.kotlin.serialization.Callable.Value" +
"er\022=\n\013return_type\030\010 \002(\0132(.org.jetbrains.", "Parameter\022=\n\013return_type\030\010 \002(\0132(.org.jet",
"kotlin.serialization.Type\032\263\001\n\016ValueParam" + "brains.kotlin.serialization.Type\032\263\001\n\016Val" +
"eter\022\r\n\005flags\030\001 \001(\005\022\014\n\004name\030\002 \002(\005\0226\n\004typ" + "ueParameter\022\r\n\005flags\030\001 \001(\005\022\014\n\004name\030\002 \002(\005" +
"e\030\003 \002(\0132(.org.jetbrains.kotlin.serializa" + "\0226\n\004type\030\003 \002(\0132(.org.jetbrains.kotlin.se" +
"tion.Type\022E\n\023vararg_element_type\030\004 \001(\0132(" + "rialization.Type\022E\n\023vararg_element_type\030" +
".org.jetbrains.kotlin.serialization.Type" + "\004 \001(\0132(.org.jetbrains.kotlin.serializati" +
"*\005\010d\020\310\001\"Q\n\nMemberKind\022\017\n\013DECLARATION\020\000\022\021" + "on.Type*\005\010d\020\310\001\"Q\n\nMemberKind\022\017\n\013DECLARAT" +
"\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELEGATION\020\002\022\017\n\013SYN" + "ION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELEGATION\020\002" +
"THESIZED\020\003\":\n\014CallableKind\022\007\n\003FUN\020\000\022\007\n\003V" + "\022\017\n\013SYNTHESIZED\020\003\":\n\014CallableKind\022\007\n\003FUN" +
"AL\020\001\022\007\n\003VAR\020\002\022\017\n\013CONSTRUCTOR\020\003*\005\010d\020\310\001*-\n" + "\020\000\022\007\n\003VAL\020\001\022\007\n\003VAR\020\002\022\017\n\013CONSTRUCTOR\020\003*\005\010" +
"\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRA", "d\020\310\001*-\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n",
"CT\020\002*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIV" + "\010ABSTRACT\020\002*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022" +
"ATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIV" + "\013\n\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022" +
"ATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005B\022B\rDebugProtoBu" + "\023\n\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005B\022B\rDebug" +
"f\210\001\000" "ProtoBuf\210\001\000"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -10,6 +10,7 @@ public final class DebugJvmProtoBuf {
registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.methodSignature); registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.methodSignature);
registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.propertySignature); registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.propertySignature);
registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.implClassName); registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.implClassName);
registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.typeAnnotation);
registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.index); registry.add(org.jetbrains.kotlin.serialization.jvm.DebugJvmProtoBuf.index);
} }
public interface JvmTypeOrBuilder public interface JvmTypeOrBuilder
@@ -3762,6 +3763,17 @@ public final class DebugJvmProtoBuf {
.newFileScopedGeneratedExtension( .newFileScopedGeneratedExtension(
java.lang.Integer.class, java.lang.Integer.class,
null); null);
public static final int TYPE_ANNOTATION_FIELD_NUMBER = 100;
/**
* <code>extend .org.jetbrains.kotlin.serialization.Type { ... }</code>
*/
public static final
com.google.protobuf.GeneratedMessage.GeneratedExtension<
org.jetbrains.kotlin.serialization.DebugProtoBuf.Type,
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>> typeAnnotation = com.google.protobuf.GeneratedMessage
.newFileScopedGeneratedExtension(
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
public static final int INDEX_FIELD_NUMBER = 100; public static final int INDEX_FIELD_NUMBER = 100;
/** /**
* <code>extend .org.jetbrains.kotlin.serialization.Callable.ValueParameter { ... }</code> * <code>extend .org.jetbrains.kotlin.serialization.Callable.ValueParameter { ... }</code>
@@ -3837,9 +3849,12 @@ public final class DebugJvmProtoBuf {
"jetbrains.kotlin.serialization.jvm.JvmPr" + "jetbrains.kotlin.serialization.jvm.JvmPr" +
"opertySignature:E\n\017impl_class_name\022,.org" + "opertySignature:E\n\017impl_class_name\022,.org" +
".jetbrains.kotlin.serialization.Callable" + ".jetbrains.kotlin.serialization.Callable" +
"\030f \001(\005:J\n\005index\022;.org.jetbrains.kotlin.s" + "\030f \001(\005:q\n\017type_annotation\022(.org.jetbrain" +
"erialization.Callable.ValueParameter\030d \001" + "s.kotlin.serialization.Type\030d \003(\0132..org." +
"(\005B\022B\020DebugJvmProtoBuf" "jetbrains.kotlin.serialization.Annotatio" +
"n:J\n\005index\022;.org.jetbrains.kotlin.serial" +
"ization.Callable.ValueParameter\030d \001(\005B\022B",
"\020DebugJvmProtoBuf"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -3873,7 +3888,8 @@ public final class DebugJvmProtoBuf {
methodSignature.internalInit(descriptor.getExtensions().get(0)); methodSignature.internalInit(descriptor.getExtensions().get(0));
propertySignature.internalInit(descriptor.getExtensions().get(1)); propertySignature.internalInit(descriptor.getExtensions().get(1));
implClassName.internalInit(descriptor.getExtensions().get(2)); implClassName.internalInit(descriptor.getExtensions().get(2));
index.internalInit(descriptor.getExtensions().get(3)); typeAnnotation.internalInit(descriptor.getExtensions().get(3));
index.internalInit(descriptor.getExtensions().get(4));
return null; return null;
} }
}; };
@@ -85,6 +85,10 @@ extend org.jetbrains.kotlin.serialization.Callable {
optional int32 impl_class_name = 102; optional int32 impl_class_name = 102;
} }
extend org.jetbrains.kotlin.serialization.Type {
repeated Annotation type_annotation = 100;
}
extend org.jetbrains.kotlin.serialization.Callable.ValueParameter { extend org.jetbrains.kotlin.serialization.Callable.ValueParameter {
// Index of the corresponding parameter of this method in JVM (counting receiver parameters, enum constructor synthetic parameters, etc.) // Index of the corresponding parameter of this method in JVM (counting receiver parameters, enum constructor synthetic parameters, etc.)
optional int32 index = 100; optional int32 index = 100;
@@ -16,23 +16,27 @@
package org.jetbrains.kotlin.load.kotlin package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass.AnnotationArrayArgumentVisitor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.storage.StorageManager
import java.util.*
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
import org.jetbrains.kotlin.resolve.constants.ErrorValue import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
import org.jetbrains.kotlin.resolve.constants.createCompileTimeConstant import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass.AnnotationArrayArgumentVisitor
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.*
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.ErrorUtils
import java.util.ArrayList
import java.util.HashMap
public class BinaryClassAnnotationAndConstantLoaderImpl( public class BinaryClassAnnotationAndConstantLoaderImpl(
private val module: ModuleDescriptor, private val module: ModuleDescriptor,
@@ -42,6 +46,13 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
) : AbstractBinaryClassAnnotationAndConstantLoader<AnnotationDescriptor, CompileTimeConstant<*>>( ) : AbstractBinaryClassAnnotationAndConstantLoader<AnnotationDescriptor, CompileTimeConstant<*>>(
storageManager, kotlinClassFinder, errorReporter storageManager, kotlinClassFinder, errorReporter
) { ) {
private val annotationDeserializer = AnnotationDeserializer(module)
override fun loadTypeAnnotations(type: ProtoBuf.Type, nameResolver: NameResolver): List<AnnotationDescriptor> {
return type.getExtension(JvmProtoBuf.typeAnnotation).map { annotation ->
annotationDeserializer.deserializeAnnotation(annotation, nameResolver)
}
}
override fun loadConstant(desc: String, initializer: Any): CompileTimeConstant<*>? { override fun loadConstant(desc: String, initializer: Any): CompileTimeConstant<*>? {
val normalizedValue: Any = if (desc in "ZBCS") { val normalizedValue: Any = if (desc in "ZBCS") {
@@ -65,7 +76,6 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
return compileTimeConstant return compileTimeConstant
} }
override fun loadAnnotation( override fun loadAnnotation(
annotationClassId: ClassId, annotationClassId: ClassId,
result: MutableList<AnnotationDescriptor> result: MutableList<AnnotationDescriptor>
@@ -10,6 +10,7 @@ public final class JvmProtoBuf {
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.methodSignature); registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.methodSignature);
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.propertySignature); registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.propertySignature);
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.implClassName); registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.implClassName);
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.typeAnnotation);
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.index); registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.index);
} }
public interface JvmTypeOrBuilder public interface JvmTypeOrBuilder
@@ -2849,6 +2850,21 @@ public final class JvmProtoBuf {
null, null,
102, 102,
com.google.protobuf.WireFormat.FieldType.INT32); com.google.protobuf.WireFormat.FieldType.INT32);
public static final int TYPE_ANNOTATION_FIELD_NUMBER = 100;
/**
* <code>extend .org.jetbrains.kotlin.serialization.Type { ... }</code>
*/
public static final
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
org.jetbrains.kotlin.serialization.ProtoBuf.Type,
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>> typeAnnotation = com.google.protobuf.GeneratedMessageLite
.newRepeatedGeneratedExtension(
org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance(),
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.getDefaultInstance(),
null,
100,
com.google.protobuf.WireFormat.FieldType.MESSAGE,
false);
public static final int INDEX_FIELD_NUMBER = 100; public static final int INDEX_FIELD_NUMBER = 100;
/** /**
* <code>extend .org.jetbrains.kotlin.serialization.Callable.ValueParameter { ... }</code> * <code>extend .org.jetbrains.kotlin.serialization.Callable.ValueParameter { ... }</code>
@@ -16,12 +16,12 @@
package org.jetbrains.kotlin.builtins package org.jetbrains.kotlin.builtins
import org.jetbrains.kotlin.serialization.*
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
class BuiltInsAnnotationAndConstantLoader( class BuiltInsAnnotationAndConstantLoader(
@@ -58,6 +58,11 @@ class BuiltInsAnnotationAndConstantLoader(
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, nameResolver) } return annotations.map { proto -> deserializer.deserializeAnnotation(proto, nameResolver) }
} }
override fun loadTypeAnnotations(proto: ProtoBuf.Type, nameResolver: NameResolver): List<AnnotationDescriptor> {
// TODO: support type annotations in built-ins
return listOf()
}
override fun loadPropertyConstant( override fun loadPropertyConstant(
container: ProtoContainer, container: ProtoContainer,
proto: ProtoBuf.Callable, proto: ProtoBuf.Callable,
@@ -443,6 +443,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private String renderDefaultType(@NotNull JetType type) { private String renderDefaultType(@NotNull JetType type) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
renderAnnotations(type, sb, /* needBrackets = */ true);
if (type.isError()) { if (type.isError()) {
sb.append(type.getConstructor().toString()); // Debug name of an error type is more informative sb.append(type.getConstructor().toString()); // Debug name of an error type is more informative
} }
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.types;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.types.checker.JetTypeChecker; import org.jetbrains.kotlin.types.checker.JetTypeChecker;
import java.util.Iterator; import java.util.Iterator;
@@ -54,19 +56,32 @@ public abstract class AbstractJetType implements JetType {
@Override @Override
public String toString() { public String toString() {
List<TypeProjection> arguments = getArguments(); StringBuilder sb = new StringBuilder();
return getConstructor() + (arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") + (isMarkedNullable() ? "?" : "");
}
private static StringBuilder argumentsToString(List<TypeProjection> arguments) { for (AnnotationDescriptor annotation : getAnnotations()) {
StringBuilder stringBuilder = new StringBuilder(); sb.append("[");
for (Iterator<TypeProjection> iterator = arguments.iterator(); iterator.hasNext();) { sb.append(DescriptorRenderer.DEBUG_TEXT.renderAnnotation(annotation));
TypeProjection argument = iterator.next(); sb.append("] ");
stringBuilder.append(argument);
if (iterator.hasNext()) {
stringBuilder.append(", ");
}
} }
return stringBuilder;
sb.append(getConstructor());
List<TypeProjection> arguments = getArguments();
if (!arguments.isEmpty()) {
sb.append("<");
for (Iterator<TypeProjection> i = arguments.iterator(); i.hasNext(); ) {
sb.append(i.next());
if (i.hasNext()) {
sb.append(", ");
}
}
sb.append(">");
}
if (isMarkedNullable()) {
sb.append("?");
}
return sb.toString();
} }
} }
+3 -1
View File
@@ -130,13 +130,15 @@ message Type {
// Id in the StringTable // Id in the StringTable
// If this field is set, the type is flexible. // If this field is set, the type is flexible.
// All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. // All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
optional int32 flexible_type_capabilities_id = 4; optional int32 flexible_type_capabilities_id = 4;
// While such an "indirect" encoding helps backwards compatibility with pre-flexible-types versions of this format, // While such an "indirect" encoding helps backwards compatibility with pre-flexible-types versions of this format,
// we use it mainly to save space: having a special mandatory tag on each an every type just to have an option // we use it mainly to save space: having a special mandatory tag on each an every type just to have an option
// to represent flexible types is too many wasted bytes. // to represent flexible types is too many wasted bytes.
optional Type flexible_upper_bound = 5; optional Type flexible_upper_bound = 5;
extensions 100 to 199;
} }
message TypeParameter { message TypeParameter {
@@ -4276,8 +4276,9 @@ public final class ProtoBuf {
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.Annotation) // @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.Annotation)
} }
public interface TypeOrBuilder public interface TypeOrBuilder extends
extends com.google.protobuf.MessageLiteOrBuilder { com.google.protobuf.GeneratedMessageLite.
ExtendableMessageOrBuilder<Type> {
// required .org.jetbrains.kotlin.serialization.Type.Constructor constructor = 1; // required .org.jetbrains.kotlin.serialization.Type.Constructor constructor = 1;
/** /**
@@ -4321,7 +4322,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
boolean hasFlexibleTypeCapabilitiesId(); boolean hasFlexibleTypeCapabilitiesId();
@@ -4331,7 +4332,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
int getFlexibleTypeCapabilitiesId(); int getFlexibleTypeCapabilitiesId();
@@ -4362,10 +4363,10 @@ public final class ProtoBuf {
* Protobuf type {@code org.jetbrains.kotlin.serialization.Type} * Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
*/ */
public static final class Type extends public static final class Type extends
com.google.protobuf.GeneratedMessageLite com.google.protobuf.GeneratedMessageLite.ExtendableMessage<
implements TypeOrBuilder { Type> implements TypeOrBuilder {
// Use Type.newBuilder() to construct. // Use Type.newBuilder() to construct.
private Type(com.google.protobuf.GeneratedMessageLite.Builder builder) { private Type(com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<org.jetbrains.kotlin.serialization.ProtoBuf.Type, ?> builder) {
super(builder); super(builder);
} }
@@ -5652,7 +5653,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public boolean hasFlexibleTypeCapabilitiesId() { public boolean hasFlexibleTypeCapabilitiesId() {
@@ -5664,7 +5665,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public int getFlexibleTypeCapabilitiesId() { public int getFlexibleTypeCapabilitiesId() {
@@ -5731,6 +5732,10 @@ public final class ProtoBuf {
return false; return false;
} }
} }
if (!extensionsAreInitialized()) {
memoizedIsInitialized = 0;
return false;
}
memoizedIsInitialized = 1; memoizedIsInitialized = 1;
return true; return true;
} }
@@ -5738,6 +5743,9 @@ public final class ProtoBuf {
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
getSerializedSize(); getSerializedSize();
com.google.protobuf.GeneratedMessageLite
.ExtendableMessage<org.jetbrains.kotlin.serialization.ProtoBuf.Type>.ExtensionWriter extensionWriter =
newExtensionWriter();
if (((bitField0_ & 0x00000001) == 0x00000001)) { if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeMessage(1, constructor_); output.writeMessage(1, constructor_);
} }
@@ -5753,6 +5761,7 @@ public final class ProtoBuf {
if (((bitField0_ & 0x00000008) == 0x00000008)) { if (((bitField0_ & 0x00000008) == 0x00000008)) {
output.writeMessage(5, flexibleUpperBound_); output.writeMessage(5, flexibleUpperBound_);
} }
extensionWriter.writeUntil(200, output);
} }
private int memoizedSerializedSize = -1; private int memoizedSerializedSize = -1;
@@ -5781,6 +5790,7 @@ public final class ProtoBuf {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
.computeMessageSize(5, flexibleUpperBound_); .computeMessageSize(5, flexibleUpperBound_);
} }
size += extensionsSerializedSize();
memoizedSerializedSize = size; memoizedSerializedSize = size;
return size; return size;
} }
@@ -5856,9 +5866,8 @@ public final class ProtoBuf {
* Protobuf type {@code org.jetbrains.kotlin.serialization.Type} * Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
*/ */
public static final class Builder extends public static final class Builder extends
com.google.protobuf.GeneratedMessageLite.Builder< com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<
org.jetbrains.kotlin.serialization.ProtoBuf.Type, Builder> org.jetbrains.kotlin.serialization.ProtoBuf.Type, Builder> implements org.jetbrains.kotlin.serialization.ProtoBuf.TypeOrBuilder {
implements org.jetbrains.kotlin.serialization.ProtoBuf.TypeOrBuilder {
// Construct using org.jetbrains.kotlin.serialization.ProtoBuf.Type.newBuilder() // Construct using org.jetbrains.kotlin.serialization.ProtoBuf.Type.newBuilder()
private Builder() { private Builder() {
maybeForceBuilderInitialization(); maybeForceBuilderInitialization();
@@ -5954,6 +5963,7 @@ public final class ProtoBuf {
if (other.hasFlexibleUpperBound()) { if (other.hasFlexibleUpperBound()) {
mergeFlexibleUpperBound(other.getFlexibleUpperBound()); mergeFlexibleUpperBound(other.getFlexibleUpperBound());
} }
this.mergeExtensionFields(other);
return this; return this;
} }
@@ -5978,6 +5988,10 @@ public final class ProtoBuf {
return false; return false;
} }
} }
if (!extensionsAreInitialized()) {
return false;
}
return true; return true;
} }
@@ -6227,7 +6241,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public boolean hasFlexibleTypeCapabilitiesId() { public boolean hasFlexibleTypeCapabilitiesId() {
@@ -6239,7 +6253,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public int getFlexibleTypeCapabilitiesId() { public int getFlexibleTypeCapabilitiesId() {
@@ -6251,7 +6265,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public Builder setFlexibleTypeCapabilitiesId(int value) { public Builder setFlexibleTypeCapabilitiesId(int value) {
@@ -6266,7 +6280,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* Id in the StringTable * Id in the StringTable
* If this field is set, the type is flexible. * If this field is set, the type is flexible.
* All the fields above represent its lower bound, and flexible_upper_bound must be set and represents its upper bound. * All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
* </pre> * </pre>
*/ */
public Builder clearFlexibleTypeCapabilitiesId() { public Builder clearFlexibleTypeCapabilitiesId() {
@@ -7793,6 +7807,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
boolean hasData(); boolean hasData();
@@ -7802,6 +7817,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
org.jetbrains.kotlin.serialization.ProtoBuf.Callable getData(); org.jetbrains.kotlin.serialization.ProtoBuf.Callable getData();
@@ -7898,6 +7914,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public boolean hasData() { public boolean hasData() {
@@ -7909,6 +7926,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.ProtoBuf.Callable getData() { public org.jetbrains.kotlin.serialization.ProtoBuf.Callable getData() {
@@ -8120,6 +8138,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public boolean hasData() { public boolean hasData() {
@@ -8131,6 +8150,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public org.jetbrains.kotlin.serialization.ProtoBuf.Callable getData() { public org.jetbrains.kotlin.serialization.ProtoBuf.Callable getData() {
@@ -8142,6 +8162,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder setData(org.jetbrains.kotlin.serialization.ProtoBuf.Callable value) { public Builder setData(org.jetbrains.kotlin.serialization.ProtoBuf.Callable value) {
@@ -8159,6 +8180,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder setData( public Builder setData(
@@ -8174,6 +8196,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder mergeData(org.jetbrains.kotlin.serialization.ProtoBuf.Callable value) { public Builder mergeData(org.jetbrains.kotlin.serialization.ProtoBuf.Callable value) {
@@ -8194,6 +8217,7 @@ public final class ProtoBuf {
* <pre> * <pre>
* If this field is present, it contains serialized data for the primary constructor. * If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization * Otherwise it's default and can be created manually upon deserialization
* Note: currently only objects have default primary constructor
* </pre> * </pre>
*/ */
public Builder clearData() { public Builder clearData() {
@@ -47,6 +47,12 @@ public interface AnnotationAndConstantLoader<A, C> {
@NotNull ProtoBuf.Callable.ValueParameter proto @NotNull ProtoBuf.Callable.ValueParameter proto
); );
@NotNull
List<A> loadTypeAnnotations(
@NotNull ProtoBuf.Type type,
@NotNull NameResolver nameResolver
);
@Nullable @Nullable
C loadPropertyConstant( C loadPropertyConstant(
@NotNull ProtoContainer container, @NotNull ProtoContainer container,
@@ -16,11 +16,13 @@
package org.jetbrains.kotlin.serialization.deserialization package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList import org.jetbrains.kotlin.utils.toReadOnlyList
@@ -42,7 +44,16 @@ class DeserializedType(
} }
private val memberScope = c.storageManager.createLazyValue { private val memberScope = c.storageManager.createLazyValue {
computeMemberScope() if (isError()) {
ErrorUtils.createErrorScope(getConstructor().toString())
}
else {
getTypeMemberScope(getConstructor(), getArguments())
}
}
private val annotations = DeserializedAnnotations(c.storageManager) {
c.components.annotationAndConstantLoader.loadTypeAnnotations(typeProto, c.nameResolver)
} }
override fun getConstructor(): TypeConstructor = constructor() override fun getConstructor(): TypeConstructor = constructor()
@@ -51,14 +62,6 @@ class DeserializedType(
override fun isMarkedNullable(): Boolean = typeProto.getNullable() override fun isMarkedNullable(): Boolean = typeProto.getNullable()
private fun computeMemberScope(): JetScope =
if (isError()) {
ErrorUtils.createErrorScope(getConstructor().toString())
}
else {
getTypeMemberScope(getConstructor(), getArguments())
}
private fun getTypeMemberScope(constructor: TypeConstructor, typeArguments: List<TypeProjection>): JetScope { private fun getTypeMemberScope(constructor: TypeConstructor, typeArguments: List<TypeProjection>): JetScope {
val descriptor = constructor.getDeclarationDescriptor() val descriptor = constructor.getDeclarationDescriptor()
return when (descriptor) { return when (descriptor) {
@@ -75,7 +78,7 @@ class DeserializedType(
return descriptor != null && ErrorUtils.isError(descriptor) return descriptor != null && ErrorUtils.isError(descriptor)
} }
override fun getAnnotations(): Annotations = Annotations.EMPTY override fun getAnnotations(): Annotations = annotations
private fun <E: Any> List<E>.getOrNull(index: Int): E? { private fun <E: Any> List<E>.getOrNull(index: Int): E? {
return if (index in indices) this[index] else null return if (index in indices) this[index] else null
@@ -92,6 +92,11 @@ class AnnotationLoaderForStubBuilder(
errorReporter: ErrorReporter errorReporter: ErrorReporter
) : AbstractBinaryClassAnnotationAndConstantLoader<ClassId, Unit>( ) : AbstractBinaryClassAnnotationAndConstantLoader<ClassId, Unit>(
LockBasedStorageManager.NO_LOCKS, kotlinClassFinder, errorReporter) { LockBasedStorageManager.NO_LOCKS, kotlinClassFinder, errorReporter) {
override fun loadTypeAnnotations(type: ProtoBuf.Type, nameResolver: NameResolver): MutableList<ClassId> {
// TODO: support type annotations in cls stubs
throw UnsupportedOperationException()
}
override fun loadConstant(desc: String, initializer: Any) = null override fun loadConstant(desc: String, initializer: Any) = null
override fun loadAnnotation(annotationClassId: ClassId, result: MutableList<ClassId>): KotlinJvmBinaryClass.AnnotationArgumentVisitor? { override fun loadAnnotation(annotationClassId: ClassId, result: MutableList<ClassId>): KotlinJvmBinaryClass.AnnotationArgumentVisitor? {
@@ -417,6 +417,33 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest {
doTest(fileName); doTest(fileName);
} }
} }
@TestMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Types extends AbstractResolveByStubTest {
public void testAllFilesPresentInTypes() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/types"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ReceiverParameter.kt")
public void testReceiverParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
doTest(fileName);
}
@TestMetadata("SimpleTypeAnnotation.kt")
public void testSimpleTypeAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt");
doTest(fileName);
}
@TestMetadata("TypeAnnotationWithArguments.kt")
public void testTypeAnnotationWithArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt");
doTest(fileName);
}
}
} }
@TestMetadata("compiler/testData/loadJava/compiledKotlin/class") @TestMetadata("compiler/testData/loadJava/compiledKotlin/class")