-
Notifications
You must be signed in to change notification settings - Fork 7
/
astwrapper.go
67 lines (54 loc) · 1.21 KB
/
astwrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package template
import "io"
type astWrapper struct {
name string
vars *astList
wrapper *astUseWrapper
body iAstNode
}
func (n *astWrapper) GetImports() []string {
res := []string{"context", "io"}
if n.body != nil {
res = append(res, n.body.GetImports()...)
}
return res
}
func (n *astWrapper) GetStrings() []string {
res := []string{}
if n.body != nil {
res = append(res, n.body.GetStrings()...)
}
return res
}
func (n *astWrapper) WriteGo(w io.Writer, opts *GenGoOpts) {
io.WriteString(w, "func Wrapper"+n.name+"(ctx context.Context, w io.Writer, tplClbF func()")
if n.vars != nil {
for _, v := range n.vars.children {
if v != nil {
io.WriteString(w, ", ")
v.WriteGo(w, opts)
}
}
}
io.WriteString(w, ") {\n")
if n.wrapper != nil {
if n.wrapper.pkgName != "" {
io.WriteString(w, n.wrapper.pkgName+".")
}
io.WriteString(w, "Wrapper"+n.wrapper.name+"(ctx, w, func() {\n")
}
if n.body != nil {
n.body.WriteGo(w, opts)
}
if n.wrapper != nil {
io.WriteString(w, "}")
if n.wrapper.params != nil {
for _, p := range n.wrapper.params.children {
io.WriteString(w, ", ")
p.WriteGo(w, opts)
}
}
io.WriteString(w, ")\n")
}
io.WriteString(w, "}\n\n")
}