Generate vocab package to multiple files.
このコミットが含まれているのは:
コミット
f155f0a3d0
|
@ -1236,6 +1236,7 @@ var (
|
|||
return b.String()
|
||||
},
|
||||
},
|
||||
Imports: []string{"time"},
|
||||
}
|
||||
xsdBooleanValueType = &ValueType{
|
||||
Name: "boolean",
|
||||
|
@ -1317,6 +1318,7 @@ var (
|
|||
return b.String()
|
||||
},
|
||||
},
|
||||
Imports: []string{"net/url"},
|
||||
}
|
||||
xsdFloatValueType = &ValueType{
|
||||
Name: "float",
|
||||
|
@ -1549,6 +1551,7 @@ var (
|
|||
return b.String()
|
||||
},
|
||||
},
|
||||
Imports: []string{"time"},
|
||||
}
|
||||
xsdNonNegativeIntegerValueType = &ValueType{
|
||||
Name: "nonNegativeInteger",
|
||||
|
@ -1904,6 +1907,7 @@ var IriValueType = &ValueType{
|
|||
return b.String()
|
||||
},
|
||||
},
|
||||
Imports: []string{"net/url"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -69,6 +69,7 @@ type ValueType struct {
|
|||
ZeroValue string
|
||||
DeserializeFn *FunctionDef
|
||||
SerializeFn *FunctionDef
|
||||
Imports []string
|
||||
}
|
||||
|
||||
type DomainReference struct {
|
||||
|
|
|
@ -22,19 +22,24 @@ const (
|
|||
unknownValueSerializeFnName = "unknownValueSerialize"
|
||||
)
|
||||
|
||||
func GenerateImplementations(types []*defs.Type, properties []*defs.PropertyType, values []*defs.ValueType) ([]byte, error) {
|
||||
type File struct {
|
||||
Name string
|
||||
Content []byte
|
||||
}
|
||||
|
||||
func GenerateImplementations(types []*defs.Type, properties []*defs.PropertyType, values []*defs.ValueType) (f []*File, err error) {
|
||||
// Validate inputs
|
||||
err := validateDomains(properties)
|
||||
err = validateDomains(properties)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
err = validateProperties(types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
err = validateValues(values, properties)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
p := generatePackageDefinition()
|
||||
|
@ -54,13 +59,40 @@ func GenerateImplementations(types []*defs.Type, properties []*defs.PropertyType
|
|||
unknown := generateUnknownValueType()
|
||||
p.F = append(p.F, unknown.DeserializeFn, unknown.SerializeFn)
|
||||
|
||||
var b []byte
|
||||
b, err = format.Source([]byte(p.Generate()))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
f = append(f, &File{
|
||||
Name: "gen_vocab.go",
|
||||
Content: b,
|
||||
})
|
||||
|
||||
for _, t := range types {
|
||||
funcs, defs, interfaces := generateDefinitions(t)
|
||||
p := &defs.PackageDef{
|
||||
Name: "vocab",
|
||||
}
|
||||
funcs, defs, interfaces, imports := generateDefinitions(t)
|
||||
imports["fmt"] = true
|
||||
for i, _ := range imports {
|
||||
p.Imports = append(p.Imports, i)
|
||||
}
|
||||
p.F = append(p.F, funcs...)
|
||||
p.Defs = append(p.Defs, defs...)
|
||||
p.I = append(p.I, interfaces...)
|
||||
|
||||
var b []byte
|
||||
b, err = format.Source([]byte(p.Generate()))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
f = append(f, &File{
|
||||
Name: fmt.Sprintf("gen_%s.go", strings.ToLower(t.Name)),
|
||||
Content: b,
|
||||
})
|
||||
}
|
||||
return format.Source([]byte(p.Generate()))
|
||||
return
|
||||
}
|
||||
|
||||
func generateTyperInterface() *defs.InterfaceDef {
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
"github.com/go-fed/activity/tools/defs"
|
||||
)
|
||||
|
||||
func generateDefinitions(t *defs.Type) (fd []*defs.FunctionDef, sd []*defs.StructDef, x []*defs.InterfaceDef) {
|
||||
func generateDefinitions(t *defs.Type) (fd []*defs.FunctionDef, sd []*defs.StructDef, x []*defs.InterfaceDef, imports map[string]bool) {
|
||||
imports = make(map[string]bool)
|
||||
this := &defs.StructDef{
|
||||
Typename: t.Name,
|
||||
Comment: t.Notes,
|
||||
|
@ -27,6 +28,13 @@ func generateDefinitions(t *defs.Type) (fd []*defs.FunctionDef, sd []*defs.Struc
|
|||
deserializeFragments = append(deserializeFragments, d)
|
||||
fd = append(fd, pf...)
|
||||
sd = append(sd, pd...)
|
||||
for _, r := range p.Range {
|
||||
if r.V != nil {
|
||||
for _, i := range r.V.Imports {
|
||||
imports[i] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
generateWithoutProperties(t, this, thisInterface)
|
||||
generateAddUnknownFunction(t, this)
|
||||
|
|
|
@ -8,12 +8,14 @@ import (
|
|||
|
||||
func main() {
|
||||
allTypes := append(defs.AllCoreTypes, defs.AllExtendedTypes...)
|
||||
b, err := gen.GenerateImplementations(allTypes, defs.AllPropertyTypes, defs.AllValueTypes)
|
||||
files, err := gen.GenerateImplementations(allTypes, defs.AllPropertyTypes, defs.AllValueTypes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = ioutil.WriteFile("vocab.go", b, 0666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
for _, f := range files {
|
||||
err = ioutil.WriteFile(f.Name, f.Content, 0666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
ファイル差分が大きすぎるため省略します
差分を読み込み
596452
vocab/vocab.go
596452
vocab/vocab.go
ファイル差分が大きすぎるため省略します
差分を読み込み
読み込み中…
新しいイシューから参照