예제 #1
0
def serialize_srg(mappings: AbstractMappings) -> Iterator[str]:
    """
    A generator that serializes the lines

    I'm not sure if this documentation is correct, since i'm not quite used to thinking of methods as object

    :param mappings: the mappings to serialize
    :return: a generator that serializes the mappings
    :raises ValueError: if the mappings are invalid
    """
    for original, renamed in mappings.classes():
        yield " ".join(["CL:", original.get_internal_name(), renamed.get_internal_name()])
    for original, renamed in mappings.fields():
        yield " ".join(["FD:", original.get_internal_name(), renamed.get_internal_name()])
    for original, renamed in mappings.methods():
        yield " ".join(
            [
                "MD:",
                # Original method
                original.get_internal_name(),
                original.get_method_signature(),
                # Renamed method
                renamed.get_internal_name(),
                renamed.get_method_signature(),
            ]
        )
def strip_duplicates(mappings: AbstractMappings) -> ImmutableMappings:
    classes = dict()  # type: Dict[Type, Type]
    fields = dict()  # type: Dict[FieldData, FieldData]
    methods = dict()  # type: Dict[MethodData, MethodData]
    for original, renamed in mappings.classes():
        if original == renamed: continue
        classes[original] = renamed
    for original, renamed in mappings.fields():
        if original.name == renamed.name: continue
        fields[original] = renamed
    for original, renamed in mappings.methods():
        if original.name == renamed.name: continue
        methods[original] = renamed
    return ImmutableMappings(classes, fields, methods)