Add Finalize method to go2idl Generator interface

This commit is contained in:
mbohlool 2016-08-30 16:37:10 -07:00
parent da4f824265
commit 641b625a2a
4 changed files with 10 additions and 0 deletions

View File

@ -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)

View File

@ -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()
}

View File

@ -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.

View File

@ -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 {