-
Notifications
You must be signed in to change notification settings - Fork 7
/
types_interface.go
68 lines (58 loc) · 1.09 KB
/
types_interface.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
package gotype
import (
"bytes"
)
type typeInterface struct {
typeBase
all types
anonymo types
method types
}
func (t *typeInterface) String() string {
buf := bytes.NewBuffer(nil)
buf.WriteString("interface{")
for i, v := range t.all {
if i != 0 {
buf.WriteString("; ")
}
buf.WriteString(v.String())
}
buf.WriteByte('}')
return buf.String()
}
func (t *typeInterface) Kind() Kind {
return Interface
}
func (t *typeInterface) NumMethod() int {
return t.method.Len()
}
func (t *typeInterface) Method(i int) Type {
return t.method.Index(i)
}
func (t *typeInterface) MethodByName(name string) (Type, bool) {
b, ok := t.method.Search(name)
if ok {
return b, true
}
for _, v := range t.anonymo {
v := v.Declaration()
b, ok := v.MethodByName(name)
if ok {
return b, true
}
}
return nil, false
}
func (t *typeInterface) NumField() int {
return t.all.Len()
}
func (t *typeInterface) Field(i int) Type {
return t.all.Index(i)
}
func (t *typeInterface) FieldByName(name string) (Type, bool) {
b, ok := t.all.Search(name)
if ok {
return b, true
}
return nil, false
}