fn tuple_serializer(&self,
                        fields: &Vec<m::JavaField>,
                        class_type: &ClassType)
                        -> Result<ClassSpec> {
        let mut serializer = ClassSpec::new(mods![Modifier::Public, Modifier::Static],
                                            "Serializer");

        serializer.extends(self.serializer.with_arguments(vec![&class_type]));

        let value = ArgumentSpec::new(mods![Modifier::Final], &class_type, "value");
        let jgen = ArgumentSpec::new(mods![Modifier::Final], &self.generator, "jgen");
        let provider = ArgumentSpec::new(mods![Modifier::Final],
                                         &self.serializer_provider,
                                         "provider");

        let mut serialize = MethodSpec::new(mods![Modifier::Public], "serialize");
        serialize.throws(&self.io_exception);
        serialize.push_argument(&value);
        serialize.push_argument(&jgen);
        serialize.push_argument(&provider);
        serialize.push_annotation(&self.override_);

        let mut body = Elements::new();
        body.push(stmt![&jgen, ".writeStartArray();"]);

        for field in fields {
            let field_stmt = stmt![&value, ".", &field.spec];

            let write = match field.ty {
                Type::Primitive(ref primitive) => {
                    match *primitive {
                        SHORT | LONG | INTEGER | FLOAT | DOUBLE => {
                            stmt!["writeNumber(", field_stmt, ")"]
                        }
                        _ => return Err("cannot serialize type".into()),
                    }
                }
                Type::Class(ref class) => {
                    if *class == self.string {
                        stmt!["writeString(", field_stmt, ")"]
                    } else {
                        stmt!["writeObject(", field_stmt, ")"]
                    }
                }
                _ => stmt!["writeObject(", field_stmt, ")"],
            };

            body.push(stmt![&jgen, ".", write, ";"]);
        }

        body.push(stmt![&jgen, ".writeEndArray();"]);

        serialize.push(body);

        serializer.push(serialize);

        Ok(serializer)
    }
/// Custom serialize implementation for tuples.
Custom serialize implementation for tuples.
Custom serialize implementation for tuples .
fn tuple_serializer(&self,
                        fields: &Vec<m::JavaField>,
                        class_type: &ClassType)
                        -> Result<ClassSpec> {
        let mut serializer = ClassSpec::new(mods![Modifier::Public, Modifier::Static],
                                            "Serializer");
        serializer.extends(self.serializer.with_arguments(vec![&class_type]));
        let value = ArgumentSpec::new(mods![Modifier::Final], &class_type, "value");
        let jgen = ArgumentSpec::new(mods![Modifier::Final], &self.generator, "jgen");
        let provider = ArgumentSpec::new(mods![Modifier::Final],
                                         &self.serializer_provider,
                                         "provider");
        let mut serialize = MethodSpec::new(mods![Modifier::Public], "serialize");
        serialize.throws(&self.io_exception);
        serialize.push_argument(&value);
        serialize.push_argument(&jgen);
        serialize.push_argument(&provider);
        serialize.push_annotation(&self.override_);
        let mut body = Elements::new();
        body.push(stmt![&jgen, ".writeStartArray();"]);
        for field in fields {
            let field_stmt = stmt![&value, ".", &field.spec];
            let write = match field.ty {
                Type::Primitive(ref primitive) => {
                    match *primitive {
                        SHORT | LONG | INTEGER | FLOAT | DOUBLE => {
                            stmt!["writeNumber(", field_stmt, ")"]
                        }
                        _ => return Err("cannot serialize type".into()),
                    }
                }
                Type::Class(ref class) => {
                    if *class == self.string {
                        stmt!["writeString(", field_stmt, ")"]
                    } else {
                        stmt!["writeObject(", field_stmt, ")"]
                    }
                }
                _ => stmt!["writeObject(", field_stmt, ")"],
            };
            body.push(stmt![&jgen, ".", write, ";"]);
        }
        body.push(stmt![&jgen, ".writeEndArray();"]);
        serialize.push(body);
        serializer.push(serialize);
        Ok(serializer)
    }
fn tuple_serializer ( & self , fields : & Vec < m :: JavaField > , class_type : & ClassType ) -> Result < ClassSpec > { let mut serializer = ClassSpec :: new ( mods ! [ Modifier Public Modifier Static ] , " " ) ; serializer . extends ( self . serializer . with_arguments ( vec ! [ class_type ] ) ) ; let value = ArgumentSpec :: new ( mods ! [ Modifier Final ] , & class_type , " " ) ; let jgen = ArgumentSpec :: new ( mods ! [ Modifier Final ] , & self . generator , " " ) ; let provider = ArgumentSpec :: new ( mods ! [ Modifier Final ] , & self . serializer_provider , " " ) ; let mut serialize = MethodSpec :: new ( mods ! [ Modifier Public ] , " " ) ; serialize . throws ( & self . io_exception ) ; serialize . push_argument ( & value ) ; serialize . push_argument ( & jgen ) ; serialize . push_argument ( & provider ) ; serialize . push_annotation ( & self . override_ ) ; let mut body = Elements :: new ( ) ; body . push ( stmt ! [ jgen " " ] ) ; for field in fields { let field_stmt = stmt ! [ value " " field spec ] ; let write = match field . ty { Type :: Primitive ( ref primitive ) => { match * primitive { SHORT | LONG | INTEGER | FLOAT | DOUBLE => { stmt ! [ " " field_stmt " " ] } _ => return Err ( " " . into ( ) ) , } } Type :: Class ( ref class ) => { if * class == self . string { stmt ! [ " " field_stmt " " ] } else { stmt ! [ " " field_stmt " " ] } } _ => stmt ! [ " " field_stmt " " ] , } ; body . push ( stmt ! [ jgen " " write " " ] ) ; } body . push ( stmt ! [ jgen " " ] ) ; serialize . push ( body ) ; serializer . push ( serialize ) ; Ok ( serializer ) }
Custom serialize implementation for tuples.
Custom serialize implementation for tuples .
&self
fields
&Vec<m::JavaField>
class_type
&ClassType
&self
fields
&Vec<m::JavaField>
class_type
&ClassType