-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
60 lines (45 loc) · 866 Bytes
/
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
package goq
import (
"go/types"
"github.com/tenntenn/optional"
)
var (
_ Query = (*Interface)(nil)
)
type embededsSeq struct {
v *types.Interface
}
func (s *embededsSeq) At(i int) interface{} {
return s.v.Embedded(i)
}
func (s *embededsSeq) Len() int {
return s.v.NumEmbeddeds()
}
type methodsSeq struct {
v *types.Interface
}
func (s *methodsSeq) At(i int) interface{} {
return s.v.Method(i)
}
func (s *methodsSeq) Len() int {
return s.v.NumMethods()
}
type Interface struct {
Empty *optional.Bool
Methods *optional.Set
Embeddeds *optional.Set
}
// Match implements Query.Match.
func (q *Interface) Match(v interface{}) bool {
t, ok := toType(v).(*types.Interface)
if !ok {
return false
}
if !q.Embeddeds.Match(&embededsSeq{v: t}) {
return false
}
if !q.Methods.Match(&methodsSeq{v: t}) {
return false
}
return true
}