-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.go
58 lines (50 loc) · 821 Bytes
/
field.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
package haste
import (
"fmt"
"go/ast"
)
type Field struct {
*ast.Field
names []string
ftype string
}
type Fields []*Field
func (f *Field) HastyType() string {
if len(f.ftype) > 0 {
return f.ftype
}
f.ftype = exprString(f.Type)
return f.ftype
}
func (f *Field) String() string {
n := f.HastyName()
if len(n) == 0 {
return f.HastyType()
}
return fmt.Sprintf("%s %s", n, f.HastyType())
}
// []string{"ctx"}
// []string{"args"}
func (f *Field) HastyNames() []string {
if len(f.names) > 0 {
return f.names
}
for _, i := range f.Names {
f.names = append(f.names, i.Name)
}
return f.names
}
// ctx
// args
func (f *Field) HastyName() string {
names := f.HastyNames()
if len(names) == 0 {
return ""
}
return names[0]
}
func NewField(f *ast.Field) *Field {
return &Field{
Field: f,
}
}