Search in sources :

Example 1 with AnnotatedWithOnlyTargetedAnnotations

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

Aggregations

AnnotatedWithOnlyTargetedAnnotations (org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations)1 KotlinTypeMapper (org.jetbrains.kotlin.codegen.state.KotlinTypeMapper)1 Annotated (org.jetbrains.kotlin.descriptors.annotations.Annotated)1 JvmMethodParameterKind (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind)1 JvmMethodParameterSignature (org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature)1