Support annotations on type aliases declarations

This commit is contained in:
Denis Zharkov
2016-06-27 19:01:00 +03:00
parent e24f0653fb
commit d53c53a900
19 changed files with 686 additions and 24 deletions
@@ -327,6 +327,8 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (old.expandedTypeId != new.expandedTypeId) return false
}
if (!checkEqualsTypeAliasAnnotation(old, new)) return false
return true
}
@@ -795,6 +797,16 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
return true
}
open fun checkEqualsTypeAliasAnnotation(old: ProtoBuf.TypeAlias, new: ProtoBuf.TypeAlias): Boolean {
if (old.annotationCount != new.annotationCount) return false
for(i in 0..old.annotationCount - 1) {
if (!checkEquals(old.getAnnotation(i), new.getAnnotation(i))) return false
}
return true
}
open fun checkEqualsTypeTableType(old: ProtoBuf.TypeTable, new: ProtoBuf.TypeTable): Boolean {
if (old.typeCount != new.typeCount) return false
@@ -1111,6 +1123,10 @@ fun ProtoBuf.TypeAlias.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int
hashCode = 31 * hashCode + expandedTypeId
}
for(i in 0..annotationCount - 1) {
hashCode = 31 * hashCode + getAnnotation(i).hashCode(stringIndexes, fqNameIndexes)
}
return hashCode
}
@@ -22266,6 +22266,30 @@ public final class DebugProtoBuf {
* <code>optional int32 expanded_type_id = 7;</code>
*/
int getExpandedTypeId();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>
getAnnotationList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation getAnnotation(int index);
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
int getAnnotationCount();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
java.util.List<? extends org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder>
getAnnotationOrBuilderList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder getAnnotationOrBuilder(
int index);
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.TypeAlias}
@@ -22374,6 +22398,14 @@ public final class DebugProtoBuf {
expandedTypeId_ = input.readInt32();
break;
}
case 66: {
if (!((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>();
mutable_bitField0_ |= 0x00000080;
}
annotation_.add(input.readMessage(org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.PARSER, extensionRegistry));
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -22385,6 +22417,9 @@ public final class DebugProtoBuf {
if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) {
typeParameter_ = java.util.Collections.unmodifiableList(typeParameter_);
}
if (((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = java.util.Collections.unmodifiableList(annotation_);
}
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
@@ -22564,6 +22599,41 @@ public final class DebugProtoBuf {
return expandedTypeId_;
}
public static final int ANNOTATION_FIELD_NUMBER = 8;
private java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation> annotation_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation> getAnnotationList() {
return annotation_;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder>
getAnnotationOrBuilderList() {
return annotation_;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public int getAnnotationCount() {
return annotation_.size();
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation getAnnotation(int index) {
return annotation_.get(index);
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder getAnnotationOrBuilder(
int index) {
return annotation_.get(index);
}
private void initFields() {
flags_ = 0;
name_ = 0;
@@ -22572,6 +22642,7 @@ public final class DebugProtoBuf {
underlyingTypeId_ = 0;
expandedType_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.Type.getDefaultInstance();
expandedTypeId_ = 0;
annotation_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -22601,6 +22672,12 @@ public final class DebugProtoBuf {
return false;
}
}
for (int i = 0; i < getAnnotationCount(); i++) {
if (!getAnnotation(i).isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
if (!extensionsAreInitialized()) {
memoizedIsInitialized = 0;
return false;
@@ -22636,6 +22713,9 @@ public final class DebugProtoBuf {
if (((bitField0_ & 0x00000020) == 0x00000020)) {
output.writeInt32(7, expandedTypeId_);
}
for (int i = 0; i < annotation_.size(); i++) {
output.writeMessage(8, annotation_.get(i));
}
extensionWriter.writeUntil(200, output);
getUnknownFields().writeTo(output);
}
@@ -22674,6 +22754,10 @@ public final class DebugProtoBuf {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(7, expandedTypeId_);
}
for (int i = 0; i < annotation_.size(); i++) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeMessageSize(8, annotation_.get(i));
}
size += extensionsSerializedSize();
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
@@ -22788,6 +22872,7 @@ public final class DebugProtoBuf {
getTypeParameterFieldBuilder();
getUnderlyingTypeFieldBuilder();
getExpandedTypeFieldBuilder();
getAnnotationFieldBuilder();
}
}
private static Builder create() {
@@ -22822,6 +22907,12 @@ public final class DebugProtoBuf {
bitField0_ = (bitField0_ & ~0x00000020);
expandedTypeId_ = 0;
bitField0_ = (bitField0_ & ~0x00000040);
if (annotationBuilder_ == null) {
annotation_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000080);
} else {
annotationBuilder_.clear();
}
return this;
}
@@ -22891,6 +22982,15 @@ public final class DebugProtoBuf {
to_bitField0_ |= 0x00000020;
}
result.expandedTypeId_ = expandedTypeId_;
if (annotationBuilder_ == null) {
if (((bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = java.util.Collections.unmodifiableList(annotation_);
bitField0_ = (bitField0_ & ~0x00000080);
}
result.annotation_ = annotation_;
} else {
result.annotation_ = annotationBuilder_.build();
}
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -22951,6 +23051,32 @@ public final class DebugProtoBuf {
if (other.hasExpandedTypeId()) {
setExpandedTypeId(other.getExpandedTypeId());
}
if (annotationBuilder_ == null) {
if (!other.annotation_.isEmpty()) {
if (annotation_.isEmpty()) {
annotation_ = other.annotation_;
bitField0_ = (bitField0_ & ~0x00000080);
} else {
ensureAnnotationIsMutable();
annotation_.addAll(other.annotation_);
}
onChanged();
}
} else {
if (!other.annotation_.isEmpty()) {
if (annotationBuilder_.isEmpty()) {
annotationBuilder_.dispose();
annotationBuilder_ = null;
annotation_ = other.annotation_;
bitField0_ = (bitField0_ & ~0x00000080);
annotationBuilder_ =
org.jetbrains.kotlin.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
getAnnotationFieldBuilder() : null;
} else {
annotationBuilder_.addAllMessages(other.annotation_);
}
}
}
this.mergeExtensionFields(other);
this.mergeUnknownFields(other.getUnknownFields());
return this;
@@ -22979,6 +23105,12 @@ public final class DebugProtoBuf {
return false;
}
}
for (int i = 0; i < getAnnotationCount(); i++) {
if (!getAnnotation(i).isInitialized()) {
return false;
}
}
if (!extensionsAreInitialized()) {
return false;
@@ -23625,6 +23757,246 @@ public final class DebugProtoBuf {
return this;
}
private java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation> annotation_ =
java.util.Collections.emptyList();
private void ensureAnnotationIsMutable() {
if (!((bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation>(annotation_);
bitField0_ |= 0x00000080;
}
}
private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder, org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder> annotationBuilder_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation> getAnnotationList() {
if (annotationBuilder_ == null) {
return java.util.Collections.unmodifiableList(annotation_);
} else {
return annotationBuilder_.getMessageList();
}
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public int getAnnotationCount() {
if (annotationBuilder_ == null) {
return annotation_.size();
} else {
return annotationBuilder_.getCount();
}
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation getAnnotation(int index) {
if (annotationBuilder_ == null) {
return annotation_.get(index);
} else {
return annotationBuilder_.getMessage(index);
}
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder setAnnotation(
int index, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation value) {
if (annotationBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
ensureAnnotationIsMutable();
annotation_.set(index, value);
onChanged();
} else {
annotationBuilder_.setMessage(index, value);
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder setAnnotation(
int index, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder builderForValue) {
if (annotationBuilder_ == null) {
ensureAnnotationIsMutable();
annotation_.set(index, builderForValue.build());
onChanged();
} else {
annotationBuilder_.setMessage(index, builderForValue.build());
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation value) {
if (annotationBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
ensureAnnotationIsMutable();
annotation_.add(value);
onChanged();
} else {
annotationBuilder_.addMessage(value);
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(
int index, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation value) {
if (annotationBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
ensureAnnotationIsMutable();
annotation_.add(index, value);
onChanged();
} else {
annotationBuilder_.addMessage(index, value);
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder builderForValue) {
if (annotationBuilder_ == null) {
ensureAnnotationIsMutable();
annotation_.add(builderForValue.build());
onChanged();
} else {
annotationBuilder_.addMessage(builderForValue.build());
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(
int index, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder builderForValue) {
if (annotationBuilder_ == null) {
ensureAnnotationIsMutable();
annotation_.add(index, builderForValue.build());
onChanged();
} else {
annotationBuilder_.addMessage(index, builderForValue.build());
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAllAnnotation(
java.lang.Iterable<? extends org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation> values) {
if (annotationBuilder_ == null) {
ensureAnnotationIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
values, annotation_);
onChanged();
} else {
annotationBuilder_.addAllMessages(values);
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder clearAnnotation() {
if (annotationBuilder_ == null) {
annotation_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000080);
onChanged();
} else {
annotationBuilder_.clear();
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder removeAnnotation(int index) {
if (annotationBuilder_ == null) {
ensureAnnotationIsMutable();
annotation_.remove(index);
onChanged();
} else {
annotationBuilder_.remove(index);
}
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder getAnnotationBuilder(
int index) {
return getAnnotationFieldBuilder().getBuilder(index);
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder getAnnotationOrBuilder(
int index) {
if (annotationBuilder_ == null) {
return annotation_.get(index); } else {
return annotationBuilder_.getMessageOrBuilder(index);
}
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder>
getAnnotationOrBuilderList() {
if (annotationBuilder_ != null) {
return annotationBuilder_.getMessageOrBuilderList();
} else {
return java.util.Collections.unmodifiableList(annotation_);
}
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder addAnnotationBuilder() {
return getAnnotationFieldBuilder().addBuilder(
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder addAnnotationBuilder(
int index) {
return getAnnotationFieldBuilder().addBuilder(
index, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder>
getAnnotationBuilderList() {
return getAnnotationFieldBuilder().getBuilderList();
}
private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder, org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder>
getAnnotationFieldBuilder() {
if (annotationBuilder_ == null) {
annotationBuilder_ = new org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation, org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.Builder, org.jetbrains.kotlin.serialization.DebugProtoBuf.AnnotationOrBuilder>(
annotation_,
((bitField0_ & 0x00000080) == 0x00000080),
getParentForChildren(),
isClean());
annotation_ = null;
}
return annotationBuilder_;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.TypeAlias)
}
@@ -24269,7 +24641,7 @@ public final class DebugProtoBuf {
"serialization.Type\022\017\n\007type_id\030\005 \001(\005\022E\n\023v" +
"ararg_element_type\030\004 \001(\0132(.org.jetbrains" +
".kotlin.serialization.Type\022\036\n\026vararg_ele",
"ment_type_id\030\006 \001(\005*\005\010d\020\310\001\"\275\002\n\tTypeAlias\022" +
"ment_type_id\030\006 \001(\005*\005\010d\020\310\001\"\201\003\n\tTypeAlias\022" +
"\020\n\005flags\030\001 \001(\005:\0010\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022I\n" +
"\016type_parameter\030\003 \003(\01321.org.jetbrains.ko" +
"tlin.serialization.TypeParameter\022A\n\017unde" +
@@ -24277,15 +24649,16 @@ public final class DebugProtoBuf {
".serialization.Type\022\032\n\022underlying_type_i" +
"d\030\005 \001(\005\022?\n\rexpanded_type\030\006 \001(\0132(.org.jet" +
"brains.kotlin.serialization.Type\022\030\n\020expa" +
"nded_type_id\030\007 \001(\005*\005\010d\020\310\001\"&\n\tEnumEntry\022\022" +
"\n\004name\030\001 \001(\005B\004\210\265\030\001*\005\010d\020\310\001*9\n\010Modality\022\t\n",
"\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n\006SEAL" +
"ED\020\003*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIV" +
"ATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIV" +
"ATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005*Q\n\nMemberKind\022\017" +
"\n\013DECLARATION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDE" +
"LEGATION\020\002\022\017\n\013SYNTHESIZED\020\003B\017B\rDebugProt" +
"oBuf"
"nded_type_id\030\007 \001(\005\022B\n\nannotation\030\010 \003(\0132." +
".org.jetbrains.kotlin.serialization.Anno",
"tation*\005\010d\020\310\001\"&\n\tEnumEntry\022\022\n\004name\030\001 \001(\005" +
"B\004\210\265\030\001*\005\010d\020\310\001*9\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004" +
"OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n\006SEALED\020\003*b\n\nVisi" +
"bility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tPRO" +
"TECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIVATE_TO_THIS\020" +
"\004\022\t\n\005LOCAL\020\005*Q\n\nMemberKind\022\017\n\013DECLARATIO" +
"N\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELEGATION\020\002\022\017" +
"\n\013SYNTHESIZED\020\003B\017B\rDebugProtoBuf"
};
org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -24401,7 +24774,7 @@ public final class DebugProtoBuf {
internal_static_org_jetbrains_kotlin_serialization_TypeAlias_fieldAccessorTable = new
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_org_jetbrains_kotlin_serialization_TypeAlias_descriptor,
new java.lang.String[] { "Flags", "Name", "TypeParameter", "UnderlyingType", "UnderlyingTypeId", "ExpandedType", "ExpandedTypeId", });
new java.lang.String[] { "Flags", "Name", "TypeParameter", "UnderlyingType", "UnderlyingTypeId", "ExpandedType", "ExpandedTypeId", "Annotation", });
internal_static_org_jetbrains_kotlin_serialization_EnumEntry_descriptor =
getDescriptor().getMessageTypes().get(13);
internal_static_org_jetbrains_kotlin_serialization_EnumEntry_fieldAccessorTable = new
@@ -306,6 +306,8 @@ class DescriptorSerializer private constructor(
builder.setExpandedType(local.type(expandedType))
}
builder.addAllAnnotation(descriptor.annotations.map { extension.annotationSerializer.serializeAnnotation(it) })
return builder
}
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.types.KotlinType
abstract class SerializerExtension {
abstract val stringTable: StringTable
val annotationSerializer by lazy { AnnotationSerializer(stringTable) }
open fun shouldUseTypeTable(): Boolean = false
open fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.types.KotlinType
open class KotlinSerializerExtensionBase(private val protocol: SerializerExtensionProtocol) : SerializerExtension() {
override final val stringTable = StringTableImpl()
private val annotationSerializer = AnnotationSerializer(stringTable)
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
for (annotation in descriptor.annotations) {
@@ -0,0 +1,9 @@
//ALLOW_AST_ACCESS
package test
annotation class Ann(val value: String = "")
@Ann()
typealias A1 = String
@Ann("OK")
typealias A2 = String
@@ -0,0 +1,10 @@
package test
@test.Ann() public typealias A1 = kotlin.String
@test.Ann(value = "OK") public typealias A2 = kotlin.String
public final annotation class Ann : kotlin.Annotation {
/*primary*/ public constructor Ann(/*0*/ value: kotlin.String = ...)
public final val value: kotlin.String
public final fun <get-value>(): kotlin.String
}
@@ -4819,6 +4819,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Annotations.kt")
public void testAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Annotations.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("Basic.kt")
public void testBasic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt");
@@ -3052,6 +3052,12 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Annotations.kt")
public void testAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Annotations.kt");
doTest(fileName);
}
@TestMetadata("Basic.kt")
public void testBasic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt");
@@ -3054,6 +3054,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Annotations.kt")
public void testAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Annotations.kt");
doTest(fileName);
}
@TestMetadata("Basic.kt")
public void testBasic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt");
@@ -348,6 +348,8 @@ message TypeAlias {
optional Type expanded_type = 6;
optional int32 expanded_type_id = 7;
repeated Annotation annotation = 8;
extensions 100 to 199;
}
@@ -17088,6 +17088,20 @@ public final class ProtoBuf {
* <code>optional int32 expanded_type_id = 7;</code>
*/
int getExpandedTypeId();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>
getAnnotationList();
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation getAnnotation(int index);
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
int getAnnotationCount();
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.TypeAlias}
@@ -17194,6 +17208,14 @@ public final class ProtoBuf {
expandedTypeId_ = input.readInt32();
break;
}
case 66: {
if (!((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>();
mutable_bitField0_ |= 0x00000080;
}
annotation_.add(input.readMessage(org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.PARSER, extensionRegistry));
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -17205,6 +17227,9 @@ public final class ProtoBuf {
if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) {
typeParameter_ = java.util.Collections.unmodifiableList(typeParameter_);
}
if (((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = java.util.Collections.unmodifiableList(annotation_);
}
try {
unknownFieldsCodedOutput.flush();
} catch (java.io.IOException e) {
@@ -17366,6 +17391,41 @@ public final class ProtoBuf {
return expandedTypeId_;
}
public static final int ANNOTATION_FIELD_NUMBER = 8;
private java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation> annotation_;
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation> getAnnotationList() {
return annotation_;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<? extends org.jetbrains.kotlin.serialization.ProtoBuf.AnnotationOrBuilder>
getAnnotationOrBuilderList() {
return annotation_;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public int getAnnotationCount() {
return annotation_.size();
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.Annotation getAnnotation(int index) {
return annotation_.get(index);
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.AnnotationOrBuilder getAnnotationOrBuilder(
int index) {
return annotation_.get(index);
}
private void initFields() {
flags_ = 0;
name_ = 0;
@@ -17374,6 +17434,7 @@ public final class ProtoBuf {
underlyingTypeId_ = 0;
expandedType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
expandedTypeId_ = 0;
annotation_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -17403,6 +17464,12 @@ public final class ProtoBuf {
return false;
}
}
for (int i = 0; i < getAnnotationCount(); i++) {
if (!getAnnotation(i).isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
if (!extensionsAreInitialized()) {
memoizedIsInitialized = 0;
return false;
@@ -17438,6 +17505,9 @@ public final class ProtoBuf {
if (((bitField0_ & 0x00000020) == 0x00000020)) {
output.writeInt32(7, expandedTypeId_);
}
for (int i = 0; i < annotation_.size(); i++) {
output.writeMessage(8, annotation_.get(i));
}
extensionWriter.writeUntil(200, output);
output.writeRawBytes(unknownFields);
}
@@ -17476,6 +17546,10 @@ public final class ProtoBuf {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(7, expandedTypeId_);
}
for (int i = 0; i < annotation_.size(); i++) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeMessageSize(8, annotation_.get(i));
}
size += extensionsSerializedSize();
size += unknownFields.size();
memoizedSerializedSize = size;
@@ -17584,6 +17658,8 @@ public final class ProtoBuf {
bitField0_ = (bitField0_ & ~0x00000020);
expandedTypeId_ = 0;
bitField0_ = (bitField0_ & ~0x00000040);
annotation_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000080);
return this;
}
@@ -17636,6 +17712,11 @@ public final class ProtoBuf {
to_bitField0_ |= 0x00000020;
}
result.expandedTypeId_ = expandedTypeId_;
if (((bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = java.util.Collections.unmodifiableList(annotation_);
bitField0_ = (bitField0_ & ~0x00000080);
}
result.annotation_ = annotation_;
result.bitField0_ = to_bitField0_;
return result;
}
@@ -17670,6 +17751,16 @@ public final class ProtoBuf {
if (other.hasExpandedTypeId()) {
setExpandedTypeId(other.getExpandedTypeId());
}
if (!other.annotation_.isEmpty()) {
if (annotation_.isEmpty()) {
annotation_ = other.annotation_;
bitField0_ = (bitField0_ & ~0x00000080);
} else {
ensureAnnotationIsMutable();
annotation_.addAll(other.annotation_);
}
}
this.mergeExtensionFields(other);
setUnknownFields(
getUnknownFields().concat(other.unknownFields));
@@ -17699,6 +17790,12 @@ public final class ProtoBuf {
return false;
}
}
for (int i = 0; i < getAnnotationCount(); i++) {
if (!getAnnotation(i).isInitialized()) {
return false;
}
}
if (!extensionsAreInitialized()) {
return false;
@@ -18118,6 +18215,131 @@ public final class ProtoBuf {
return this;
}
private java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation> annotation_ =
java.util.Collections.emptyList();
private void ensureAnnotationIsMutable() {
if (!((bitField0_ & 0x00000080) == 0x00000080)) {
annotation_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation>(annotation_);
bitField0_ |= 0x00000080;
}
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public java.util.List<org.jetbrains.kotlin.serialization.ProtoBuf.Annotation> getAnnotationList() {
return java.util.Collections.unmodifiableList(annotation_);
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public int getAnnotationCount() {
return annotation_.size();
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.Annotation getAnnotation(int index) {
return annotation_.get(index);
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder setAnnotation(
int index, org.jetbrains.kotlin.serialization.ProtoBuf.Annotation value) {
if (value == null) {
throw new NullPointerException();
}
ensureAnnotationIsMutable();
annotation_.set(index, value);
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder setAnnotation(
int index, org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Builder builderForValue) {
ensureAnnotationIsMutable();
annotation_.set(index, builderForValue.build());
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(org.jetbrains.kotlin.serialization.ProtoBuf.Annotation value) {
if (value == null) {
throw new NullPointerException();
}
ensureAnnotationIsMutable();
annotation_.add(value);
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(
int index, org.jetbrains.kotlin.serialization.ProtoBuf.Annotation value) {
if (value == null) {
throw new NullPointerException();
}
ensureAnnotationIsMutable();
annotation_.add(index, value);
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(
org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Builder builderForValue) {
ensureAnnotationIsMutable();
annotation_.add(builderForValue.build());
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAnnotation(
int index, org.jetbrains.kotlin.serialization.ProtoBuf.Annotation.Builder builderForValue) {
ensureAnnotationIsMutable();
annotation_.add(index, builderForValue.build());
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder addAllAnnotation(
java.lang.Iterable<? extends org.jetbrains.kotlin.serialization.ProtoBuf.Annotation> values) {
ensureAnnotationIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
values, annotation_);
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder clearAnnotation() {
annotation_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000080);
return this;
}
/**
* <code>repeated .org.jetbrains.kotlin.serialization.Annotation annotation = 8;</code>
*/
public Builder removeAnnotation(int index) {
ensureAnnotationIsMutable();
annotation_.remove(index);
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.TypeAlias)
}
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
import org.jetbrains.kotlin.utils.toReadOnlyList
class MemberDeserializer(private val c: DeserializationContext) {
private val annotationDeserializer = AnnotationDeserializer(c.components.moduleDescriptor, c.components.notFoundClasses)
fun loadProperty(proto: ProtoBuf.Property): PropertyDescriptor {
val flags = if (proto.hasFlags()) proto.flags else loadOldFlags(proto.oldFlags)
@@ -173,7 +175,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
}
fun loadTypeAlias(proto: ProtoBuf.TypeAlias): TypeAliasDescriptor {
val annotations = Annotations.EMPTY // TODO generate & load type alias annotations
val annotations = AnnotationsImpl(proto.annotationList.map { annotationDeserializer.deserializeAnnotation(it, c.nameResolver) })
val visibility = Deserialization.visibility(Flags.VISIBILITY.get(proto.flags))
val typeAlias = DeserializedTypeAliasDescriptor(
@@ -18,15 +18,12 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.flags.VISIBILITY
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.stubs.impl.KotlinTypeAliasStubImpl
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
fun createTypeAliasStub(
parent: StubElement<out PsiElement>,
@@ -46,7 +43,7 @@ fun createTypeAliasStub(
parent, classId.shortClassName.ref(), classId.asSingleFqName().ref(),
isTopLevel = !classId.isNestedClass)
createModifierListStubForDeclaration(typeAlias, typeAliasProto.flags, arrayListOf(VISIBILITY), listOf())
val modifierList = createModifierListStubForDeclaration(typeAlias, typeAliasProto.flags, arrayListOf(VISIBILITY), listOf())
val typeStubBuilder = TypeClsStubBuilder(context)
val restConstraints = typeStubBuilder.createTypeParameterListStub(typeAlias, typeAliasProto.typeParameterList)
@@ -55,8 +52,7 @@ fun createTypeAliasStub(
}
if (Flags.HAS_ANNOTATIONS.get(typeAliasProto.flags)) {
// TODO: support annotations
// createAnnotationStubs(context.components.annotationLoader.loadClassAnnotations(thisAsProtoContainer), modifierList)
createAnnotationStubs(typeAliasProto.annotationList.map { context.nameResolver.getClassId(it.id) }, modifierList)
}
typeStubBuilder.createTypeReferenceStub(typeAlias, typeAliasProto.underlyingType)
@@ -8,5 +8,5 @@ public final class TypeAliases public constructor() {
public typealias B = (dependency.A) -> kotlin.Unit
private typealias Parametrized<E, F> = kotlin.collections.Map<E, F>
@test.Ann private typealias Parametrized<E, F> = kotlin.collections.Map<E, F>
}
@@ -8,7 +8,7 @@ class Outer<E, F> {
}
}
annotation class Ann
annotation class Ann(val value: String)
class TypeAliases {
typealias B = (A) -> Unit
@@ -17,7 +17,6 @@ class TypeAliases {
b.invoke(a)
}
// TODO: annotations are unsupported yet
@Ann
@Ann("OK")
private typealias Parametrized<E, F> = Map<E, F>
}
@@ -17,7 +17,6 @@ class TypeAliases {
b.invoke(a)
}
// TODO: annotations are unsupported yet
@Ann
private typealias Parametrized<E, F> = Map<E, F>
}
@@ -85,6 +85,13 @@ PsiJetFileStubImpl[package=test]
REFERENCE_EXPRESSION:[referencedName=Unit]
TYPEALIAS:[fqName=test.TypeAliases.Parametrized, isTopLevel=false, name=Parametrized]
MODIFIER_LIST:[private]
ANNOTATION_ENTRY:[hasValueArguments=false, shortName=Ann]
CONSTRUCTOR_CALLEE:
TYPE_REFERENCE:
USER_TYPE:
USER_TYPE:
REFERENCE_EXPRESSION:[referencedName=test]
REFERENCE_EXPRESSION:[referencedName=Ann]
TYPE_PARAMETER_LIST:
TYPE_PARAMETER:[fqName=null, isInVariance=false, isOutVariance=false, name=E]
TYPE_PARAMETER:[fqName=null, isInVariance=false, isOutVariance=false, name=F]
@@ -3052,6 +3052,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Annotations.kt")
public void testAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Annotations.kt");
doTest(fileName);
}
@TestMetadata("Basic.kt")
public void testBasic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt");