// NewCodeGen . func NewCodeGen(rootpath string, skips []string) (gslang.Visitor, error) { codeGen := &_CodeGen{ Log: gslogger.Get("gen4go"), rootpath: rootpath, prefix: make(map[string]string), } for _, skip := range skips { exp, err := regexp.Compile(skip) if err != nil { return nil, gserrors.Newf(err, "invalid skip regex string :%s", skip) } codeGen.skips = append(codeGen.skips, exp) } funcs := template.FuncMap{ "title": codeGen.title, "title2": strings.Title, "enumFields": codeGen.enumFields, "typeName": codeGen.typeName, "enumRead": codeGen.enumRead, "enumWrite": codeGen.enumWrite, "fieldDecl": codeGen.fieldDecl, "defaultVal": codeGen.defaultVal, "marshalField": codeGen.marshalField, "unmarshalField": codeGen.unmarshalField, "methodDecl": codeGen.methodDecl, "rpcMethodDecl": codeGen.rpcMethodDecl, "unmarshalParam": codeGen.unmarshalParam, "marshalParam": codeGen.marshalParam, "methodCall": codeGen.methodCall, "marshalReturn": codeGen.marshalReturn, "unmarshalReturn": codeGen.unmarshalReturn, "notVoid": gslang.NotVoid, "isPOD": gslang.IsPOD, "isAsync": gslang.IsAsync, "isException": gslang.IsException, "enumSize": gslang.EnumSize, "enumType": func(typeDecl ast.Type) string { return builtin[gslang.EnumType(typeDecl)] }, "builtin": gslang.IsBuiltin, "marshalParams": codeGen.marshalParams, "callback": codeGen.callback, "tagValue": codeGen.tagValue, } tpl, err := template.New("t4objc").Funcs(funcs).Parse(t4objc) if err != nil { return nil, err } codeGen.tpl = tpl return codeGen, nil }
// NewCodeGen . func NewCodeGen(rootpath string, skips []string) (gslang.Visitor, error) { codeGen := &_CodeGen{ Log: gslogger.Get("gen4go"), rootpath: rootpath, } for _, skip := range skips { exp, err := regexp.Compile(skip) if err != nil { return nil, gserrors.Newf(err, "invalid skip regex string :%s", skip) } codeGen.skips = append(codeGen.skips, exp) } funcs := template.FuncMap{ "title": strings.Title, "enumType": func(typeDecl ast.Type) string { return builtin[gslang.EnumType(typeDecl)] }, "notVoid": gslang.NotVoid, "isPOD": gslang.IsPOD, "isAsync": gslang.IsAsync, "isException": gslang.IsException, "enumSize": gslang.EnumSize, "builtin": gslang.IsBuiltin, "typeName": codeGen.typeName, "defaultVal": codeGen.defaultVal, "readType": codeGen.readType, "writeType": codeGen.writeType, "params": codeGen.params, "returnParam": codeGen.returnParam, "callArgs": codeGen.callArgs, "returnArgs": codeGen.returnArgs, "tagValue": codeGen.tagValue, } tpl, err := template.New("gen4go").Funcs(funcs).Parse(tpl4go) if err != nil { return nil, err } codeGen.tpl = tpl return codeGen, nil }
// NewCodeGen . func NewCodeGen(rootpath string, skips []string) (gslang.Visitor, error) { codeGen := &_CodeGen{ Log: gslogger.Get("gen4go"), rootpath: rootpath, } for _, skip := range skips { exp, err := regexp.Compile(skip) if err != nil { return nil, gserrors.Newf(err, "invalid skip regex string :%s", skip) } codeGen.skips = append(codeGen.skips, exp) } funcs := template.FuncMap{ "exception": exception, "title": strings.Title, "tableName": func(typeDecl ast.Type) string { if gslang.IsException(typeDecl) { return exception(strings.Title(typeDecl.Name())) } return strings.Title(typeDecl.Name()) }, "methodName": methodName, "fieldName": fieldname, "enumFields": codeGen.enumFields, "notVoid": gslang.NotVoid, "isPOD": gslang.IsPOD, "isAsync": gslang.IsAsync, "isException": gslang.IsException, "enumSize": gslang.EnumSize, "enumType": func(typeDecl ast.Type) string { return builtin[gslang.EnumType(typeDecl)] }, "builtin": gslang.IsBuiltin, "typeName": codeGen.typeName, "objTypeName": codeGen.objTypeName, "defaultVal": codeGen.defaultVal, "readType": codeGen.readType, "writeType": codeGen.writeType, "params": codeGen.params, "returnParam": codeGen.returnParam, "callArgs": codeGen.callArgs, "returnArgs": codeGen.returnArgs, "marshalField": codeGen.marshalfield, "unmarshalField": codeGen.unmarshalfield, "unmarshalParam": codeGen.unmarshalParam, "methodcall": codeGen.methodcall, "marshalParam": codeGen.marshalParam, "marshalReturn": codeGen.marshalReturn, "methodRPC": codeGen.methodRPC, "marshalParams": codeGen.marshalParams, "callback": codeGen.callback, "unmarshalReturn": codeGen.unmarshalReturn, "constructor": codeGen.constructor, "tagValue": codeGen.tagValue, } tpl, err := template.New("t4java").Funcs(funcs).Parse(t4java) if err != nil { return nil, err } codeGen.tpl = tpl return codeGen, nil }