-
Notifications
You must be signed in to change notification settings - Fork 8
/
info.go
69 lines (61 loc) · 1.36 KB
/
info.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
69
package gotype
// info holds result type information.
// Only the information for which a map is provided is collected.
// If the package has type errors, the collected information may be incomplete.
type info struct {
PkgNamed map[string]types // map[file]packgae
Named types // var, func, type,
Methods map[string]types // map[type]method
Src string
PkgPath string
Goroot bool
}
type infoFile struct {
*info
filename string
}
func newInfo(src string, pkg string, goroot bool) *info {
return &info{
Src: src,
PkgPath: pkg,
Goroot: goroot,
Methods: map[string]types{},
PkgNamed: map[string]types{},
}
}
func (i *info) File(filename string) *infoFile {
return &infoFile{
info: i,
filename: filename,
}
}
func (i *infoFile) GetPkgOrType(name string) (Type, bool) {
if pkg, ok := i.PkgNamed[i.filename]; ok {
t, ok := pkg.Search(name)
if ok {
return t, ok
}
}
if i.filename == "" {
for _, pkg := range i.PkgNamed {
t, ok := pkg.Search(name)
if ok {
return t, ok
}
}
}
return i.Named.Search(name)
}
func (i *infoFile) AddPkg(t Type) {
pkg, _ := i.PkgNamed[i.filename]
pkg.Add(t)
i.PkgNamed[i.filename] = pkg
}
func (i *infoFile) AddType(t Type) {
i.Named.Add(t)
}
func (i *infoFile) AddMethod(name string, t Type) {
methods := i.Methods[name]
methods.Add(t)
i.Methods[name] = methods
}