Skip to content

migrate_called_after_annotation

Source code in src/library_analyzer/processing/migration/annotations/_migrate_called_after_annotation.py
def migrate_called_after_annotation(
    origin_annotation: CalledAfterAnnotation,
    mapping: Mapping,
    mappings: list[Mapping],
) -> list[AbstractAnnotation]:
    migrated_annotations: list[AbstractAnnotation] = []
    for element in mapping.get_apiv2_elements():
        called_after_annotation = deepcopy(origin_annotation)
        authors = called_after_annotation.authors
        authors.append(migration_author)
        called_after_annotation.authors = authors
        if not isinstance(element, Function):
            if not isinstance(element, Attribute | Result):
                migrated_annotations.append(
                    TodoAnnotation(
                        element.id,
                        authors,
                        called_after_annotation.reviewers,
                        called_after_annotation.comment,
                        EnumReviewResult.NONE,
                        get_migration_text(called_after_annotation, mapping, for_todo_annotation=True),
                    ),
                )
            continue

        called_before_functions = _get_function_called_before_replacements(called_after_annotation, mappings, element)
        if len(called_before_functions) == 1 and called_before_functions[0] != element:
            migrated_annotations.append(
                CalledAfterAnnotation(
                    element.id,
                    authors,
                    called_after_annotation.reviewers,
                    called_after_annotation.comment,
                    called_after_annotation.reviewResult,
                    called_before_functions[0].name,
                ),
            )
        else:
            migrated_annotations.append(
                TodoAnnotation(
                    element.id,
                    authors,
                    called_after_annotation.reviewers,
                    called_after_annotation.comment,
                    EnumReviewResult.NONE,
                    get_migration_text(
                        called_after_annotation,
                        mapping,
                        for_todo_annotation=True,
                        additional_information=called_before_functions,
                    ),
                ),
            )
    return migrated_annotations