How to use the stone.ir.is_list_type function in stone

To help you get started, we’ve selected a few stone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dropbox / dropbox-sdk-go-unofficial / generator / go_types.stoneg.py View on Github external
if needs_base_type(struct):
            self.emit('// UnmarshalJSON deserializes into a %s instance' % struct.name)
            with self.block('func (u *%s) UnmarshalJSON(b []byte) error' % struct.name):
                with self.block('type wrap struct'):
                    for field in struct.all_fields:
                        self._generate_field(field, namespace=struct.namespace,
                                             raw=_needs_base_type(field.data_type))
                self.emit('var w wrap')
                with self.block('if err := json.Unmarshal(b, &w); err != nil'):
                    self.emit('return err')
                for field in struct.all_fields:
                    dt = field.data_type
                    fn = fmt_var(field.name)
                    tn = fmt_type(dt, namespace=struct.namespace, use_interface=True)
                    if _needs_base_type(dt):
                        if is_list_type(dt):
                            self.emit("u.{0} = make({1}, len(w.{0}))".format(fn, tn))
                            # Grab the underlying type to get the correct Is...FromJSON method
                            tn = fmt_type(dt.data_type, namespace=struct.namespace, use_interface=True)
                            with self.block("for i, e := range w.{0}".format(fn)):
                                self.emit("v, err := {1}FromJSON(e)".format(fn, tn))
                                with self.block('if err != nil'):
                                    self.emit('return err')
                                self.emit("u.{0}[i] = v".format(fn))
                        else:
                            self.emit("{0}, err := {1}FromJSON(w.{0})".format(fn, tn))
                            with self.block('if err != nil'):
                                self.emit('return err')
                            self.emit("u.{0} = {0}".format(fn))
                    else:
                        self.emit("u.{0} = w.{0}".format(fn))
                self.emit('return nil')
github dropbox / stone / stone / backends / tsd_helpers.py View on Github external
def fmt_type_name(data_type, inside_namespace=None):
    """
    Produces a TypeScript type name for the given data type.
    inside_namespace should be set to the namespace that the reference
    occurs in, or None if this parameter is not relevant.
    """
    if is_user_defined_type(data_type) or is_alias(data_type):
        if data_type.namespace == inside_namespace:
            return data_type.name
        else:
            return '%s.%s' % (data_type.namespace.name, data_type.name)
    else:
        fmted_type = _base_type_table.get(data_type.__class__, 'Object')
        if is_list_type(data_type):
            fmted_type += '<' + fmt_type(data_type.data_type, inside_namespace) + '>'
        return fmted_type
github dropbox / stone / stone / backends / swift.py View on Github external
def fmt_serial_obj(data_type):
    data_type, nullable = unwrap_nullable(data_type)

    if is_user_defined_type(data_type):
        result = '{}.{}Serializer()'
        result = result.format(fmt_class(data_type.namespace.name),
            fmt_class(data_type.name))
    else:
        result = _serial_type_table.get(data_type.__class__, fmt_class(data_type.name))

        if is_list_type(data_type):
            result = result + '({})'.format(fmt_serial_obj(data_type.data_type))
        elif is_timestamp_type(data_type):
            result = result + '("{}")'.format(data_type.format)
        else:
            result = 'Serialization._{}'.format(result)

    return result if not nullable else 'NullableSerializer({})'.format(result)
github dropbox / stone / stone / backends / js_helpers.py View on Github external
def fmt_type_name(data_type):
    """
    Returns the JSDoc name for the given data type.
    (Does not attempt to enumerate subtypes.)
    """
    if is_user_defined_type(data_type):
        return fmt_pascal('%s%s' % (data_type.namespace.name, data_type.name))
    else:
        fmted_type = _base_type_table.get(data_type.__class__, 'Object')
        if is_list_type(data_type):
            fmted_type += '.<' + fmt_type(data_type.data_type) + '>'
        return fmted_type
github dropbox / stone / stone / backends / tsd_helpers.py View on Github external
def fmt_type_name(data_type, inside_namespace=None):
    """
    Produces a TypeScript type name for the given data type.
    inside_namespace should be set to the namespace that the reference
    occurs in, or None if this parameter is not relevant.
    """
    if is_user_defined_type(data_type) or is_alias(data_type):
        if data_type.namespace == inside_namespace:
            return data_type.name
        else:
            return '%s.%s' % (data_type.namespace.name, data_type.name)
    else:
        fmted_type = _base_type_table.get(data_type.__class__, 'Object')
        if is_list_type(data_type):
            fmted_type += '<' + fmt_type(data_type.data_type, inside_namespace) + '>'
        elif is_map_type(data_type):
            key_data_type = _base_type_table.get(data_type.key_data_type, 'string')
            value_data_type = fmt_type_name(data_type.value_data_type, inside_namespace)
            fmted_type = '{[key: %s]: %s}' % (key_data_type, value_data_type)
        return fmted_type
github rclone / rclone / vendor / github.com / dropbox / dropbox-sdk-go-unofficial / generator / go_helpers.py View on Github external
def fmt_type(data_type, namespace=None, use_interface=False):
    data_type, nullable = unwrap_nullable(data_type)
    if is_list_type(data_type):
        return '[]%s' % fmt_type(data_type.data_type, namespace, use_interface)
    type_name = data_type.name
    if use_interface and _needs_base_type(data_type):
        type_name = 'Is' + type_name
    if is_composite_type(data_type) and namespace is not None and \
            namespace.name != data_type.namespace.name:
        type_name = data_type.namespace.name + '.' + type_name
    if use_interface and _needs_base_type(data_type):
        return _type_table.get(data_type.__class__, type_name)
    else:
        return _type_table.get(data_type.__class__, '*' + type_name)