-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgo_call.go
78 lines (58 loc) · 1.14 KB
/
go_call.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
68
69
70
71
72
73
74
75
76
77
78
package gocoder
import (
"go/ast"
"go/token"
)
type GoCall struct {
rootExpr *GoExpr
args []*GoExpr
goFun *GoExpr
astCall *ast.CallExpr
}
func newGoCall(rootExpr *GoExpr, astCall *ast.CallExpr) *GoCall {
g := &GoCall{
rootExpr: rootExpr,
astCall: astCall,
}
g.load()
return g
}
func (p *GoCall) load() {
p.goFun = newGoExpr(p.rootExpr, p.astCall.Fun)
for _, arg := range p.astCall.Args {
newArg := newGoExpr(
p.rootExpr,
arg)
p.args = append(p.args, newArg)
}
}
func (p *GoCall) Name() string {
switch callFunc := p.astCall.Fun.(type) {
case *ast.Ident:
{
return callFunc.Name
}
case *ast.SelectorExpr:
{
return callFunc.Sel.Name
}
}
return ""
}
func (p *GoCall) Func() *GoExpr {
return p.goFun
}
func (p *GoCall) Arg(i int) *GoExpr {
return p.args[i]
}
func (p *GoCall) NumArgs() int {
return len(p.args)
}
func (p *GoCall) goNode() {
}
func (p *GoCall) Position() (token.Position, token.Position) {
return p.rootExpr.astFileSet.Position(p.astCall.Pos()), p.rootExpr.astFileSet.Position(p.astCall.End())
}
func (p *GoCall) Print() error {
return ast.Print(p.rootExpr.astFileSet, p.astCall)
}