Search in sources :

Example 1 with AccessorForPropertyDescriptor

use of org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor in project kotlin by JetBrains.

the class FieldOwnerContext method getFieldName.

@NotNull
public String getFieldName(@NotNull PropertyDescriptor possiblySubstitutedDescriptor, boolean isDelegated) {
    if (possiblySubstitutedDescriptor instanceof AccessorForPropertyDescriptor) {
        possiblySubstitutedDescriptor = ((AccessorForPropertyDescriptor) possiblySubstitutedDescriptor).getCalleeDescriptor();
    }
    PropertyDescriptor descriptor = possiblySubstitutedDescriptor.getOriginal();
    assert descriptor.getKind().isReal() : "Only declared properties can have backing fields: " + descriptor;
    String defaultPropertyName = KotlinTypeMapper.mapDefaultFieldName(descriptor, isDelegated);
    Map<PropertyDescriptor, String> descriptor2Name = fieldNames.get(defaultPropertyName);
    if (descriptor2Name == null) {
        descriptor2Name = new HashMap<PropertyDescriptor, String>();
        fieldNames.put(defaultPropertyName, descriptor2Name);
    }
    String actualName = descriptor2Name.get(descriptor);
    if (actualName != null)
        return actualName;
    String newName = descriptor2Name.isEmpty() || AnnotationUtilKt.hasJvmFieldAnnotation(descriptor) ? defaultPropertyName : defaultPropertyName + "$" + descriptor2Name.size();
    descriptor2Name.put(descriptor, newName);
    return newName;
}
Also used : AccessorForPropertyDescriptor(org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor) PropertyDescriptor(org.jetbrains.kotlin.descriptors.PropertyDescriptor) AccessorForPropertyDescriptor(org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 AccessorForPropertyDescriptor (org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor)1 PropertyDescriptor (org.jetbrains.kotlin.descriptors.PropertyDescriptor)1