-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgo_field_list.go
67 lines (50 loc) · 1.21 KB
/
go_field_list.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 gocoder
import (
"go/ast"
"go/token"
)
type GoFieldList struct {
rootExpr *GoExpr
astExpr *ast.FieldList
goFields []*GoField
}
func newFieldList(rootExpr *GoExpr, astFieldList *ast.FieldList) *GoFieldList {
gfl := &GoFieldList{
rootExpr: rootExpr,
astExpr: astFieldList,
}
gfl.load()
return gfl
}
func (p *GoFieldList) Print() error {
return ast.Print(p.rootExpr.astFileSet, p.astExpr)
}
func (p *GoFieldList) NumFields() int {
return p.astExpr.NumFields()
}
func (p *GoFieldList) Field(i int) *GoField {
return p.goFields[i]
}
func (p *GoFieldList) TypesAre(paramsType ...string) bool {
if p.astExpr.NumFields() != len(paramsType) {
return false
}
for i := 0; i < p.astExpr.NumFields(); i++ {
if !isFieldTypeOf(p.astExpr.List[i], paramsType[i]) {
return false
}
}
return true
}
func (p *GoFieldList) Position() (token.Position, token.Position) {
return p.rootExpr.astFileSet.Position(p.astExpr.Pos()), p.rootExpr.astFileSet.Position(p.astExpr.End())
}
func (p *GoFieldList) load() {
if p.astExpr == nil {
return
}
for i := 0; i < len(p.astExpr.List); i++ {
p.goFields = append(p.goFields, newGoField(p.rootExpr, p.astExpr.List[i]))
}
}
func (p *GoFieldList) goNode() {}