-
Notifications
You must be signed in to change notification settings - Fork 8
/
types_importer.go
81 lines (68 loc) · 1.2 KB
/
types_importer.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
70
71
72
73
74
75
76
77
78
79
80
81
package gotype
func newTypeImport(name, path string, src string, imp importer) Type {
return &typeImport{
name: name,
path: path,
src: src,
imp: imp,
}
}
type typeImport struct {
typeBase
name string
path string
src string
imp importer
scope Type
}
func (t *typeImport) check() {
if t.scope != nil {
return
}
s, err := t.imp.Import(t.path, t.src)
if err != nil {
t.imp.appendError(err)
}
t.scope = s
}
func (t *typeImport) PkgPath() string {
return t.path
}
func (t *typeImport) IsGoroot() bool {
_, ok := t.imp.ImportName(t.path, t.src)
return ok
}
func (t *typeImport) String() string {
return t.path
}
func (t *typeImport) Name() string {
if t.name != "" {
return t.name
}
t.name, _ = t.imp.ImportName(t.path, t.src)
return t.name
}
func (t *typeImport) Kind() Kind {
return Scope
}
func (t *typeImport) ChildByName(name string) (Type, bool) {
t.check()
if t.scope == nil {
return nil, false
}
return t.scope.ChildByName(name)
}
func (t *typeImport) Child(i int) Type {
t.check()
if t.scope == nil {
return nil
}
return t.scope.Child(i)
}
func (t *typeImport) NumChild() int {
t.check()
if t.scope == nil {
return 0
}
return t.scope.NumChild()
}