-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathastcondition.go
61 lines (46 loc) · 1.05 KB
/
astcondition.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
package template
import "io"
type astCondition struct {
condition iAstNode
ifBody iAstNode
elseBody iAstNode
}
func (n *astCondition) GetImports() []string {
res := []string{}
if n.condition != nil {
res = append(res, n.condition.GetImports()...)
}
if n.ifBody != nil {
res = append(res, n.ifBody.GetImports()...)
}
if n.elseBody != nil {
res = append(res, n.elseBody.GetImports()...)
}
return res
}
func (n *astCondition) GetStrings() []string {
res := []string{}
if n.condition != nil {
res = append(res, n.condition.GetStrings()...)
}
if n.ifBody != nil {
res = append(res, n.ifBody.GetStrings()...)
}
if n.elseBody != nil {
res = append(res, n.elseBody.GetStrings()...)
}
return res
}
func (n *astCondition) WriteGo(w io.Writer, opts *GenGoOpts) {
io.WriteString(w, "if ")
n.condition.WriteGo(w, opts)
io.WriteString(w, " {\n")
n.ifBody.WriteGo(w, opts)
io.WriteString(w, "}")
if n.elseBody != nil {
io.WriteString(w, " else {\n")
n.elseBody.WriteGo(w, opts)
io.WriteString(w, "}")
}
io.WriteString(w, "\n")
}