-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.go
48 lines (42 loc) · 932 Bytes
/
ast.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
package main
import (
"errors"
"fmt"
)
func NewMethodsCollection(ifaceName string, srcDir string) (*MethodsCollection, error) {
path, id, err := findInterface(ifaceName, srcDir)
if err != nil {
return nil, err
}
m := &MethodsCollection{
Path: path,
ID: id,
}
methods, srcPath, err := methodsOf(path, id, ifaceName, srcDir)
if err != nil {
return nil, err
}
m.Methods = methods
m.SrcPath = srcPath
return m, nil
}
type MethodsCollection struct {
Path string
SrcPath string
ID string
Methods []Method
}
var ErrStopRange = errors.New("stop range")
func (m *MethodsCollection) ForEachMethod(fn func(m *Method) error) error {
for _, mm := range m.Methods {
if err := fn(&mm); err == ErrStopRange {
return nil
} else if err != nil {
return err
}
}
return nil
}
func (m *MethodsCollection) String() string {
return fmt.Sprintf("(%s) %s: %d methods", m.Path, m.ID, len(m.Methods))
}