Search in sources :

Example 1 with AnnotatedWithFakeAnnotations

use of org.jetbrains.kotlin.codegen.annotation.AnnotatedWithFakeAnnotations 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

AnnotatedWithFakeAnnotations (org.jetbrains.kotlin.codegen.annotation.AnnotatedWithFakeAnnotations)1 Annotated (org.jetbrains.kotlin.descriptors.annotations.Annotated)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 FieldVisitor (org.jetbrains.org.objectweb.asm.FieldVisitor)1 Type (org.jetbrains.org.objectweb.asm.Type)1