Exemple #1
0
 def generate_member_variable(name: str) -> Member:
     member_variable = Member("python")
     member_variable.kind = "variable"
     member_variable.name = name
     member_variable.returns = ReturnValue()
     member_variable.returns.type = TypeRef("python")
     return member_variable
Exemple #2
0
def objc_class():
    compound = Compound("objc")
    compound.name = "MyClass"

    def generate_member(kind: str, prot: str) -> Member:
        member = Member("objc")
        member.kind = kind
        member.name = prot.capitalize() + kind.capitalize()
        member.prot = prot
        return member

    def generate_member_function(prot: str,
                                 name: str,
                                 has_return_value: bool = True,
                                 is_static: bool = False) -> Member:
        member = Member("objc")
        member.kind = "function"
        member.name = name
        member.prot = prot
        if has_return_value:
            member.returns = ReturnValue()
        if is_static:
            member.static = True
        return member

    def generate_property(prot: str) -> Member:
        property = generate_member_function(prot=prot,
                                            name=prot.capitalize() +
                                            "Property")
        property.kind = "property"
        return property

    # fill class with typical members
    for visibility in ("public", "protected", "private"):
        for member_type in ("enum", "class", "protocol", "trash"):
            compound.members.append(
                generate_member(kind=member_type, prot=visibility))

        # add property
        compound.members.append(generate_property(prot=visibility))
        # add some method
        compound.members.append(
            generate_member_function(prot=visibility,
                                     name=visibility.capitalize() + "Method"))
        # add static method
        compound.members.append(
            generate_member_function(prot=visibility,
                                     name=visibility.capitalize() +
                                     "StaticMethod",
                                     is_static=True))

    # forbidden method
    member = Member("objc")
    member.kind = "function"
    member.name = "NS_UNAVAILABLE"
    member.prot = "public"
    member.returns = ReturnValue()
    compound.members.append(member)

    return compound
Exemple #3
0
def test_objc_method_signature__class_method(context):
    method = Member("objc")
    method.name = "start"
    method.static = True
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="void")
    assert objc_method_signature(method, context) == "+ (void)start"
Exemple #4
0
def test_objc_method_signature__multiple_params_linked_return(context):
    method = Member("objc")
    method.name = "setValue:withUnit:andALongerParam:"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="Value")
    method.returns.type.id = "objc-value"

    param1 = Parameter()
    param1.name = "arg1"
    param1.type = TypeRef("objc", "Type1")

    param2 = Parameter()
    param2.name = "arg2"
    param2.type = TypeRef("objc", "Type2")
    param2.type.id = "objc-type2"

    param3 = Parameter()
    param3.name = "arg3"
    param3.type = TypeRef("objc", "Type3")

    method.params = [param1, param2, param3]

    assert (objc_method_signature(
        method, context) == "- (xref:objc-value[Value])setValue:(Type1)arg1\n"
            "         withUnit:(xref:objc-type2[Type2])arg2\n"
            "  andALongerParam:(Type3)arg3")
Exemple #5
0
def test_objc_method_signature__no_params_link_return(context):
    method = Member("objc")
    method.name = "retrieveValue"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="Value")
    method.returns.type.id = "objc-value"
    assert objc_method_signature(
        method, context) == "- (xref:objc-value[Value])retrieveValue"
Exemple #6
0
 def generate_member_function(name: str,
                              has_return_value: bool = True,
                              is_static: bool = False) -> Member:
     member = Member("python")
     member.kind = "function"
     member.name = name
     member.prot = "public"
     if has_return_value:
         member.returns = ReturnValue()
     if is_static:
         member.static = True
     return member
Exemple #7
0
def test_objc_method_signature__one_param(context):
    method = Member("objc")
    method.name = "setValue:"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="Value")
    method.returns.type.id = "objc-value"

    param1 = Parameter()
    param1.name = "arg1"
    param1.type = TypeRef("objc", "Type1")
    method.params = [param1]

    assert objc_method_signature(
        method, context) == "- (xref:objc-value[Value])setValue:(Type1)arg1"
Exemple #8
0
 def generate_member(kind: str, prot: str) -> Member:
     member = Member("cpp")
     member.kind = kind
     member.name = prot.capitalize() + kind.capitalize()
     member.prot = prot
     return member
Exemple #9
0
def test_objc_method_signature__no_params_simple_return(context):
    method = Member("objc")
    method.name = "start"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="void")
    assert objc_method_signature(method, context) == "- (void)start"