Search in sources :

Example 1 with Annotated

use of org.jetbrains.kotlin.descriptors.annotations.Annotated in project kotlin by JetBrains.

the class FunctionCodegen method generateParameterAnnotations.

public static void generateParameterAnnotations(@NotNull FunctionDescriptor functionDescriptor, @NotNull MethodVisitor mv, @NotNull JvmMethodSignature jvmSignature, @NotNull List<ValueParameterDescriptor> valueParameters, @NotNull InnerClassConsumer innerClassConsumer, @NotNull GenerationState state) {
    KotlinTypeMapper typeMapper = state.getTypeMapper();
    Iterator<ValueParameterDescriptor> iterator = valueParameters.iterator();
    List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getValueParameters();
    for (int i = 0; i < kotlinParameterTypes.size(); i++) {
        JvmMethodParameterSignature parameterSignature = kotlinParameterTypes.get(i);
        JvmMethodParameterKind kind = parameterSignature.getKind();
        if (kind.isSkippedInGenericSignature()) {
            markEnumOrInnerConstructorParameterAsSynthetic(mv, i, state.getClassBuilderMode());
            continue;
        }
        if (kind == JvmMethodParameterKind.VALUE) {
            ValueParameterDescriptor parameter = iterator.next();
            AnnotationCodegen annotationCodegen = AnnotationCodegen.forParameter(i, mv, innerClassConsumer, typeMapper);
            if (functionDescriptor instanceof PropertySetterDescriptor) {
                PropertyDescriptor propertyDescriptor = ((PropertySetterDescriptor) functionDescriptor).getCorrespondingProperty();
                Annotated targetedAnnotations = new AnnotatedWithOnlyTargetedAnnotations(propertyDescriptor);
                annotationCodegen.genAnnotations(targetedAnnotations, parameterSignature.getAsmType(), SETTER_PARAMETER);
            }
            if (functionDescriptor instanceof ConstructorDescriptor) {
                annotationCodegen.genAnnotations(parameter, parameterSignature.getAsmType(), CONSTRUCTOR_PARAMETER);
            } else {
                annotationCodegen.genAnnotations(parameter, parameterSignature.getAsmType());
            }
        } else if (kind == JvmMethodParameterKind.RECEIVER) {
            ReceiverParameterDescriptor receiver = JvmCodegenUtil.getDirectMember(functionDescriptor).getExtensionReceiverParameter();
            if (receiver != null) {
                AnnotationCodegen annotationCodegen = AnnotationCodegen.forParameter(i, mv, innerClassConsumer, typeMapper);
                Annotated targetedAnnotations = new AnnotatedWithOnlyTargetedAnnotations(receiver.getType());
                annotationCodegen.genAnnotations(targetedAnnotations, parameterSignature.getAsmType(), RECEIVER);
                annotationCodegen.genAnnotations(receiver, parameterSignature.getAsmType());
            }
        }
    }
}
Also used : JvmMethodParameterSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature) JvmMethodParameterKind(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind) Annotated(org.jetbrains.kotlin.descriptors.annotations.Annotated) AnnotatedWithOnlyTargetedAnnotations(org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations) KotlinTypeMapper(org.jetbrains.kotlin.codegen.state.KotlinTypeMapper)

Example 2 with Annotated

use of org.jetbrains.kotlin.descriptors.annotations.Annotated in project kotlin by JetBrains.

the class PackagePartCodegen method generateAnnotationsForPartClass.

private void generateAnnotationsForPartClass() {
    List<AnnotationDescriptor> fileAnnotationDescriptors = new ArrayList<AnnotationDescriptor>();
    for (KtAnnotationEntry annotationEntry : element.getAnnotationEntries()) {
        AnnotationDescriptor annotationDescriptor = state.getBindingContext().get(BindingContext.ANNOTATION, annotationEntry);
        if (annotationDescriptor != null) {
            fileAnnotationDescriptors.add(annotationDescriptor);
        }
    }
    Annotated annotatedFile = new AnnotatedSimple(new AnnotationsImpl(fileAnnotationDescriptors));
    AnnotationCodegen.forClass(v.getVisitor(), this, state.getTypeMapper()).genAnnotations(annotatedFile, null);
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) Annotated(org.jetbrains.kotlin.descriptors.annotations.Annotated) ArrayList(java.util.ArrayList) AnnotatedSimple(org.jetbrains.kotlin.codegen.annotation.AnnotatedSimple) AnnotationsImpl(org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl)

Example 3 with Annotated

use of org.jetbrains.kotlin.descriptors.annotations.Annotated in project kotlin by JetBrains.

the class PropertyCodegen method generateBackingField.

private void generateBackingField(KtNamedDeclaration element, PropertyDescriptor propertyDescriptor, boolean isDelegate, KotlinType kotlinType, Object defaultValue, Annotations annotations) {
    int modifiers = getDeprecatedAccessFlag(propertyDescriptor);
    for (AnnotationCodegen.JvmFlagAnnotation flagAnnotation : AnnotationCodegen.FIELD_FLAGS) {
        if (flagAnnotation.hasAnnotation(propertyDescriptor.getOriginal())) {
            modifiers |= flagAnnotation.getJvmFlag();
        }
    }
    if (kind == OwnerKind.PACKAGE) {
        modifiers |= ACC_STATIC;
    }
    if (!propertyDescriptor.isLateInit() && (!propertyDescriptor.isVar() || isDelegate)) {
        modifiers |= ACC_FINAL;
    }
    if (AnnotationUtilKt.hasJvmSyntheticAnnotation(propertyDescriptor)) {
        modifiers |= ACC_SYNTHETIC;
    }
    Type type = typeMapper.mapType(kotlinType);
    ClassBuilder builder = v;
    FieldOwnerContext backingFieldContext = context;
    if (AsmUtil.isInstancePropertyWithStaticBackingField(propertyDescriptor)) {
        modifiers |= ACC_STATIC;
        if (JvmAbi.isPropertyWithBackingFieldInOuterClass(propertyDescriptor)) {
            ImplementationBodyCodegen codegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
            builder = codegen.v;
            backingFieldContext = codegen.context;
        }
    }
    modifiers |= getVisibilityForBackingField(propertyDescriptor, isDelegate);
    if (AsmUtil.isPropertyWithBackingFieldCopyInOuterClass(propertyDescriptor)) {
        ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
        parentBodyCodegen.addCompanionObjectPropertyToCopy(propertyDescriptor, defaultValue);
    }
    String name = backingFieldContext.getFieldName(propertyDescriptor, isDelegate);
    v.getSerializationBindings().put(FIELD_FOR_PROPERTY, propertyDescriptor, Pair.create(type, name));
    FieldVisitor fv = builder.newField(JvmDeclarationOriginKt.OtherOrigin(element, propertyDescriptor), modifiers, name, type.getDescriptor(), isDelegate ? null : typeMapper.mapFieldSignature(kotlinType, propertyDescriptor), defaultValue);
    Annotated fieldAnnotated = new AnnotatedWithFakeAnnotations(propertyDescriptor, annotations);
    AnnotationCodegen.forField(fv, memberCodegen, typeMapper).genAnnotations(fieldAnnotated, type, isDelegate ? AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD : AnnotationUseSiteTarget.FIELD);
}
Also used : Annotated(org.jetbrains.kotlin.descriptors.annotations.Annotated) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type(org.jetbrains.org.objectweb.asm.Type) AnnotatedWithFakeAnnotations(org.jetbrains.kotlin.codegen.annotation.AnnotatedWithFakeAnnotations) FieldVisitor(org.jetbrains.org.objectweb.asm.FieldVisitor)

Aggregations

Annotated (org.jetbrains.kotlin.descriptors.annotations.Annotated)3 ArrayList (java.util.ArrayList)1 AnnotatedSimple (org.jetbrains.kotlin.codegen.annotation.AnnotatedSimple)1 AnnotatedWithFakeAnnotations (org.jetbrains.kotlin.codegen.annotation.AnnotatedWithFakeAnnotations)1 AnnotatedWithOnlyTargetedAnnotations (org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations)1 KotlinTypeMapper (org.jetbrains.kotlin.codegen.state.KotlinTypeMapper)1 AnnotationDescriptor (org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor)1 AnnotationsImpl (org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl)1 JvmMethodParameterKind (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind)1 JvmMethodParameterSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 FieldVisitor (org.jetbrains.org.objectweb.asm.FieldVisitor)1 Type (org.jetbrains.org.objectweb.asm.Type)1