Ejemplo n.º 1
0
def v1_generate_simple_serialize_method(method_name: str, fields: List[SerializingField]) -> List[StatementBlock]:
    arr_elements = []

    for field in fields:
        lval = '$this->{0}'.format(field.name())
        substituted_lval = lval

        if field.convert_func() is not None:
            substituted_lval = field.convert_func().format(expr=substituted_lval)

        arr_elements.append(ArrayElementDeclaration(
            field.serialized_name(),
            AnyEvaluation("is_null({0}) ? null : {1}".format(lval, substituted_lval), Type.any())
        ))

    class_fields = [
        DocCommentStatement(
            None, [
                Annotation.returns("array")
            ]
        ),
        MethodDeclaration(
            Identifier(method_name), Type.array(), AccessModifier.public(), False,
            ArgumentListDeclaration([]),
            MethodBody([
                ReturnStatement(ArrayDeclaration(True, arr_elements))
            ])
        )
    ]

    return class_fields
Ejemplo n.º 2
0
def v1_generate_members(spec: Spec) -> List[StatementBlock]:
    class_fields = []

    for field in spec.fields():
        class_fields.append(DocCommentStatement(
            field.comment(), [
                Annotation.types(field.type())
            ]
        ))
        class_fields.append(MemberDeclaration(
            Identifier(field.name()), Type(field.type()), AccessModifier.public(), False
        ))

    return class_fields
Ejemplo n.º 3
0
def v1_generate_simple_deserialize_method(
        method_name: str, clazz: str, n: int, fields: List[DeserializingField]
) -> List[StatementBlock]:
    parameters = []

    for index in range(n):
        parameters.append(AnyEvaluation("null", Type.any()))

    for field in fields:
        lval = '$data["{0}"]'.format(field.serialized_name())
        substituted_lval = lval

        if field.convert_func() is not None:
            substituted_lval = field.convert_func().format(expr=substituted_lval)

        parameters[field.position()] = AnyEvaluation(
            "isset({0}) ? {1} : null".format(lval, substituted_lval), Type(field.type())
        )

    class_fields = [
        DocCommentStatement(
            None, [
                Annotation.param("data", Type.dictionary().represent())
            ]
        ),
        MethodDeclaration(
            Identifier(method_name), Type(clazz), AccessModifier.public(), True,
            ArgumentListDeclaration([
                ArgumentDeclaration(Identifier("data"), Type.dictionary()),
            ]),
            MethodBody([
                ReturnStatement(
                    InvocationStatement(
                        NamedCallableReference("new {0}".format(clazz)), Type(clazz),
                        ParameterList(parameters)
                    )
                )
            ])
        )
    ]

    return class_fields
Ejemplo n.º 4
0
 def instanceof():
     return UnaryOperator(Type.boolean(), "instanceof")
Ejemplo n.º 5
0
 def not_double_equal():
     return UnaryOperator(Type.boolean(), "!=")
Ejemplo n.º 6
0
 def not_triple_equal():
     return UnaryOperator(Type.boolean(), "!==")
Ejemplo n.º 7
0
 def less_than_or_equal():
     return UnaryOperator(Type.boolean(), "<=")
Ejemplo n.º 8
0
 def less_than():
     return UnaryOperator(Type.boolean(), "<")
Ejemplo n.º 9
0
 def great_than_or_equal():
     return UnaryOperator(Type.boolean(), ">=")
Ejemplo n.º 10
0
 def great_than():
     return UnaryOperator(Type.boolean(), ">")
Ejemplo n.º 11
0
 def double_equal():
     return UnaryOperator(Type.boolean(), "==")
Ejemplo n.º 12
0
 def triple_equal():
     return UnaryOperator(Type.boolean(), "===")
Ejemplo n.º 13
0
 def type(self) -> Type:
     return Type.array()