Search in sources :

Example 1 with TypeAliasDescriptor

use of org.jetbrains.kotlin.descriptors.TypeAliasDescriptor in project kotlin by JetBrains.

the class PackagePartCodegen method generateKotlinMetadataAnnotation.

@Override
protected void generateKotlinMetadataAnnotation() {
    List<DeclarationDescriptor> members = new ArrayList<DeclarationDescriptor>();
    for (KtDeclaration declaration : element.getDeclarations()) {
        if (declaration instanceof KtNamedFunction) {
            SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
            members.add(functionDescriptor);
        } else if (declaration instanceof KtProperty) {
            VariableDescriptor property = bindingContext.get(BindingContext.VARIABLE, declaration);
            members.add(property);
        } else if (declaration instanceof KtTypeAlias) {
            TypeAliasDescriptor typeAlias = bindingContext.get(BindingContext.TYPE_ALIAS, declaration);
            members.add(typeAlias);
        }
    }
    final DescriptorSerializer serializer = DescriptorSerializer.createTopLevel(new JvmSerializerExtension(v.getSerializationBindings(), state));
    final ProtoBuf.Package packageProto = serializer.packagePartProto(element.getPackageFqName(), members).build();
    WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.FILE_FACADE, 0, new Function1<AnnotationVisitor, Unit>() {

        @Override
        public Unit invoke(AnnotationVisitor av) {
            writeAnnotationData(av, serializer, packageProto);
            return Unit.INSTANCE;
        }
    });
}
Also used : JvmSerializerExtension(org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension) TypeAliasDescriptor(org.jetbrains.kotlin.descriptors.TypeAliasDescriptor) ArrayList(java.util.ArrayList) VariableDescriptor(org.jetbrains.kotlin.descriptors.VariableDescriptor) Unit(kotlin.Unit) ProtoBuf(org.jetbrains.kotlin.serialization.ProtoBuf) DescriptorSerializer(org.jetbrains.kotlin.serialization.DescriptorSerializer) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) AnnotationVisitor(org.jetbrains.org.objectweb.asm.AnnotationVisitor) SimpleFunctionDescriptor(org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)

Aggregations

ArrayList (java.util.ArrayList)1 Unit (kotlin.Unit)1 JvmSerializerExtension (org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 SimpleFunctionDescriptor (org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor)1 TypeAliasDescriptor (org.jetbrains.kotlin.descriptors.TypeAliasDescriptor)1 VariableDescriptor (org.jetbrains.kotlin.descriptors.VariableDescriptor)1 DescriptorSerializer (org.jetbrains.kotlin.serialization.DescriptorSerializer)1 ProtoBuf (org.jetbrains.kotlin.serialization.ProtoBuf)1 AnnotationVisitor (org.jetbrains.org.objectweb.asm.AnnotationVisitor)1