Commit 641b625a authored by mbohlool's avatar mbohlool

Add Finalize method to go2idl Generator interface

parent da4f8242
......@@ -50,6 +50,7 @@ func (d DefaultGen) PackageConsts(*Context) []string { retur
func (d DefaultGen) GenerateType(*Context, *types.Type, io.Writer) error { return nil }
func (d DefaultGen) Filename() string { return d.OptionalName + ".go" }
func (d DefaultGen) FileType() string { return GolangFileType }
func (d DefaultGen) Finalize(*Context, io.Writer) error { return nil }
func (d DefaultGen) Init(c *Context, w io.Writer) error {
_, err := w.Write(d.OptionalBody)
......
......@@ -302,5 +302,8 @@ func (c *Context) executeBody(w io.Writer, generator Generator) error {
return err
}
}
if err := generator.Finalize(c, et); err != nil {
return err
}
return et.Error()
}
......@@ -110,6 +110,11 @@ type Generator interface {
// Generators.)
Init(*Context, io.Writer) error
// Finalize should write finish up codes, and any other content that's not
// generated per-type. For example if you are generating one block (function,
// type, etc) for all types, this function can be used to close the block.
Finalize(*Context, io.Writer) error
// PackageVars should emit an array of variable lines. They will be
// placed in a var ( ... ) block. There's no need to include a leading
// \t or trailing \n.
......
......@@ -252,6 +252,7 @@ func (r *importRules) GenerateType(*generator.Context, *types.Type, io.Writer) e
func (r *importRules) Filename() string { return ".import-restrictions" }
func (r *importRules) FileType() string { return importBossFileType }
func (r *importRules) Init(c *generator.Context, w io.Writer) error { return nil }
func (r *importRules) Finalize(c *generator.Context, w io.Writer) error { return nil }
func dfsImports(dest *[]string, seen map[string]bool, p *types.Package) {
for _, p2 := range p.Imports {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment