示例#1
0
    def _GenerateCType(self, ctype, file):
        for deptype in ctype.getDependentTypes():
            if deptype.getName() in self._top_level_map:
                continue
            self._GenerateCType(deptype, file)

        decl = """
type %(camel)s struct {
""" % {'camel': ctype.getName()}
        file.write(decl)
        for member in ctype.getDataMembers():
            camel = CamelCase(member.membername)
            ptrType = False
            if member.isComplex:
                mtype = member.xsd_object.getType()
                if not member.isSequence:
                    ptrType = True
            else:
                mtype = getGoLangType(member.xsd_object.getType())
            if member.isSequence:
                mtype = '[]' + mtype
            decl = '\t%s %s%s `json:"%s,omitempty"`\n' % \
                   (camel, '*' if ptrType else '', mtype, member.membername)
            file.write(decl)
        file.write('}\n')

        # Generate methods (add/delete/clear/set) for sequence fields
        for member in ctype.getDataMembers():
            if not member.isSequence:
                continue
            membertype = member.xsd_object.getType()
            if not member.isComplex:
                membertype = getGoLangType(membertype)
            decl = """
func (obj *%(typecamel)s) Add%(fieldcamel)s(value %(ptr)s%(fieldtype)s) {
        obj.%(member)s = append(obj.%(member)s, %(ptr)svalue)
}
""" \
            % {'typecamel': ctype.getName(),
               'fieldcamel': CamelCase(member.membername),
               'fieldtype': membertype,
               'ptr': '*' if member.isComplex else '',
               'member': CamelCase(member.membername),
               }
            file.write(decl)

        # mark as generated
        ctypename = ctype.getName()
        self._top_level_map[ctypename] = self._type_map[ctypename]
示例#2
0
    def _GenerateCType(self, ctype, file):
        for deptype in ctype.getDependentTypes():
            if deptype.getName() in self._top_level_map:
                continue
            self._GenerateCType(deptype, file)

        decl = """
type %(camel)s struct {
""" % {'camel': ctype.getName()}
        file.write(decl)
        for member in ctype.getDataMembers():
            camel = CamelCase(member.membername)
            ptrType = False
            if member.isComplex:
                mtype = member.xsd_object.getType()
                if not member.isSequence:
                    ptrType = True
            else:
                mtype = getGoLangType(member.xsd_object.getType())
            if member.isSequence:
                mtype = '[]' + mtype
            decl = '\t%s %s%s `json:"%s,omitempty"`\n' % \
                   (camel, '*' if ptrType else '', mtype, member.membername)
            file.write(decl)
        file.write('}\n')

        # Generate methods (add/delete/clear/set) for sequence fields
        for member in ctype.getDataMembers():
            if not member.isSequence:
                continue
            membertype = member.xsd_object.getType()
            if not member.isComplex:
                membertype = getGoLangType(membertype)
            decl = """
func (obj *%(typecamel)s) Add%(fieldcamel)s(value %(ptr)s%(fieldtype)s) {
        obj.%(member)s = append(obj.%(member)s, %(ptr)svalue)
}
""" \
            % {'typecamel': ctype.getName(),
               'fieldcamel': CamelCase(member.membername),
               'fieldtype': membertype,
               'ptr': '*' if member.isComplex else '',
               'member': CamelCase(member.membername),
               }
            file.write(decl)

        # mark as generated
        ctypename = ctype.getName()
        self._top_level_map[ctypename] = self._type_map[ctypename]
示例#3
0
 def getGoLangTypename(self):
     if self._xelement.isComplex():
         return self._complexType.getName()
     return getGoLangType(self._xelement.getType())
 def getGoLangTypename(self):
     if self._xelement.isComplex():
         return self._complexType.getName()
     return getGoLangType(self._xelement.getType())