瀏覽代碼

Fix bug: replace int and float with num type in dart (#3042)

Co-authored-by: zhoumingji <zhoumingji@cmsr.chinamobile.com>
Snake 2 年之前
父節點
當前提交
a561048d59
共有 3 個文件被更改,包括 12 次插入2 次删除
  1. 2 2
      tools/goctl/api/dartgen/gendata.go
  2. 9 0
      tools/goctl/api/dartgen/util.go
  3. 1 0
      tools/goctl/api/dartgen/vars.go

+ 2 - 2
tools/goctl/api/dartgen/gendata.go

@@ -13,7 +13,7 @@ const dataTemplate = `// --{{with .Info}}{{.Title}}{{end}}--
 class {{.Name}}{
 	{{range .Members}}
 	/// {{.Comment}}
-	final {{.Type.Name}} {{lowCamelCase .Name}};
+	final {{if isNumberType .Type.Name}}num{{else}}{{.Type.Name}}{{end}} {{lowCamelCase .Name}};
 	{{end}}
 	{{.Name}}({ {{range .Members}}
 		this.{{lowCamelCase .Name}},{{end}}
@@ -37,7 +37,7 @@ const dataTemplateV2 = `// --{{with .Info}}{{.Title}}{{end}}--
 class {{.Name}} {
 	{{range .Members}}
 	{{if .Comment}}{{.Comment}}{{end}}
-	final {{.Type.Name}} {{lowCamelCase .Name}};
+	final {{if isNumberType .Type.Name}}num{{else}}{{.Type.Name}}{{end}} {{lowCamelCase .Name}};
   {{end}}{{.Name}}({{if .Members}}{
 	{{range .Members}}  required this.{{lowCamelCase .Name}},
 	{{end}}}{{end}});

+ 9 - 0
tools/goctl/api/dartgen/util.go

@@ -57,6 +57,15 @@ func isAtomicType(s string) bool {
 	}
 }
 
+func isNumberType(s string) bool {
+	switch s {
+	case "int", "double":
+		return true
+	default:
+		return false
+	}
+}
+
 func isListType(s string) bool {
 	return strings.HasPrefix(s, "List<")
 }

+ 1 - 0
tools/goctl/api/dartgen/vars.go

@@ -6,6 +6,7 @@ var funcMap = template.FuncMap{
 	"getBaseName":                     getBaseName,
 	"getPropertyFromMember":           getPropertyFromMember,
 	"isDirectType":                    isDirectType,
+	"isNumberType":                    isNumberType,
 	"isClassListType":                 isClassListType,
 	"getCoreType":                     getCoreType,
 	"lowCamelCase":                    lowCamelCase,