Skip to content

Commit bcc4601

Browse files
committed
Add Finalize method to Generator interface.
1 parent 03e942a commit bcc4601

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

examples/import-boss/generators/import_restrict.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (r *importRules) GenerateType(*generator.Context, *types.Type, io.Writer) e
252252
func (r *importRules) Filename() string { return ".import-restrictions" }
253253
func (r *importRules) FileType() string { return importBossFileType }
254254
func (r *importRules) Init(c *generator.Context, w io.Writer) error { return nil }
255+
func (r *importRules) Finalize(*generator.Context, io.Writer) error { return nil }
255256

256257
func dfsImports(dest *[]string, seen map[string]bool, p *types.Package) {
257258
for _, p2 := range p.Imports {

generator/default_generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (d DefaultGen) PackageConsts(*Context) []string { retur
5050
func (d DefaultGen) GenerateType(*Context, *types.Type, io.Writer) error { return nil }
5151
func (d DefaultGen) Filename() string { return d.OptionalName + ".go" }
5252
func (d DefaultGen) FileType() string { return GolangFileType }
53+
func (d DefaultGen) Finalize(*Context, io.Writer) error { return nil }
5354

5455
func (d DefaultGen) Init(c *Context, w io.Writer) error {
5556
_, err := w.Write(d.OptionalBody)

generator/execute.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,8 @@ func (c *Context) executeBody(w io.Writer, generator Generator) error {
302302
return err
303303
}
304304
}
305+
if err := generator.Finalize(c, et); err != nil {
306+
return err
307+
}
305308
return et.Error()
306309
}

generator/generator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ type Generator interface {
110110
// Generators.)
111111
Init(*Context, io.Writer) error
112112

113+
// Finalize should write finish up functions, and any other content that's not
114+
// generated per-type.
115+
Finalize(*Context, io.Writer) error
116+
113117
// PackageVars should emit an array of variable lines. They will be
114118
// placed in a var ( ... ) block. There's no need to include a leading
115119
// \t or trailing \n.

0 commit comments

Comments
 (0)