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

Co-authored-by: zhoumingji <zhoumingji@cmsr.chinamobile.com>
master
Snake 2 years ago committed by GitHub
parent 7a647ca40c
commit a561048d59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -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 { func isListType(s string) bool {
return strings.HasPrefix(s, "List<") return strings.HasPrefix(s, "List<")
} }

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

Loading…
Cancel
Save