You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
622 B
36 lines
622 B
package gogen
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/format"
|
|
"go/token"
|
|
"io"
|
|
)
|
|
|
|
type Package struct {
|
|
Name string
|
|
Declarations []Declaration
|
|
}
|
|
|
|
func (me *Package) Declare(decl Declaration) *Package {
|
|
me.Declarations = append(me.Declarations, decl)
|
|
return me
|
|
}
|
|
|
|
func (me *Package) Ast() ast.Node {
|
|
decls := make([]ast.Decl, len(me.Declarations))
|
|
for i, decl := range me.Declarations {
|
|
decls[i] = decl.Declaration()
|
|
}
|
|
return &ast.File{
|
|
Name: &ast.Ident{
|
|
Name: me.Name,
|
|
},
|
|
Decls: decls,
|
|
}
|
|
}
|
|
|
|
func (me *Package) WriteTo(w io.Writer) error {
|
|
fset := token.NewFileSet()
|
|
return format.Node(w, fset, me.Ast())
|
|
}
|
|
|