Search in sources :

Example 1 with AnnotationVisitor

use of org.jetbrains.org.objectweb.asm.AnnotationVisitor 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)

Example 2 with AnnotationVisitor

use of org.jetbrains.org.objectweb.asm.AnnotationVisitor in project kotlin by JetBrains.

the class ClosureCodegen method generateKotlinMetadataAnnotation.

@Override
protected void generateKotlinMetadataAnnotation() {
    FunctionDescriptor frontendFunDescriptor = CodegenUtilKt.unwrapFrontendVersion(funDescriptor);
    FunctionDescriptor freeLambdaDescriptor = createFreeLambdaDescriptor(frontendFunDescriptor);
    Method method = v.getSerializationBindings().get(METHOD_FOR_FUNCTION, frontendFunDescriptor);
    assert method != null : "No method for " + frontendFunDescriptor;
    v.getSerializationBindings().put(METHOD_FOR_FUNCTION, freeLambdaDescriptor, method);
    final DescriptorSerializer serializer = DescriptorSerializer.createForLambda(new JvmSerializerExtension(v.getSerializationBindings(), state));
    final ProtoBuf.Function functionProto = serializer.functionProto(freeLambdaDescriptor).build();
    WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.SYNTHETIC_CLASS, 0, new Function1<AnnotationVisitor, Unit>() {

        @Override
        public Unit invoke(AnnotationVisitor av) {
            writeAnnotationData(av, serializer, functionProto);
            return Unit.INSTANCE;
        }
    });
}
Also used : JvmSerializerExtension(org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension) DescriptorSerializer(org.jetbrains.kotlin.serialization.DescriptorSerializer) AnnotationVisitor(org.jetbrains.org.objectweb.asm.AnnotationVisitor) Method(org.jetbrains.org.objectweb.asm.commons.Method) Unit(kotlin.Unit) ProtoBuf(org.jetbrains.kotlin.serialization.ProtoBuf)

Aggregations

Unit (kotlin.Unit)2 JvmSerializerExtension (org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension)2 DescriptorSerializer (org.jetbrains.kotlin.serialization.DescriptorSerializer)2 ProtoBuf (org.jetbrains.kotlin.serialization.ProtoBuf)2 AnnotationVisitor (org.jetbrains.org.objectweb.asm.AnnotationVisitor)2 ArrayList (java.util.ArrayList)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 Method (org.jetbrains.org.objectweb.asm.commons.Method)1