/
types_origin.go
56 lines (48 loc) · 896 Bytes
/
types_origin.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
package gotype
import (
"go/ast"
)
func newTypeOrigin(v Type, ori ast.Node, info *info, doc, comment *ast.CommentGroup) Type {
pkg := info.PkgPath
goroot := info.Goroot || v.IsGoroot()
if p := v.PkgPath(); p != "" {
pkg = p
}
if doc == nil {
doc = v.Doc()
}
if comment == nil {
comment = v.Comment()
}
return &typeOrigin{
Type: v,
pkgPath: pkg,
goroot: goroot,
ori: ori,
doc: doc,
comment: comment,
}
}
type typeOrigin struct {
Type
ori ast.Node
pkgPath string
goroot bool
doc *ast.CommentGroup
comment *ast.CommentGroup
}
func (t *typeOrigin) Origin() ast.Node {
return t.ori
}
func (t *typeOrigin) PkgPath() string {
return t.pkgPath
}
func (t *typeOrigin) IsGoroot() bool {
return t.goroot
}
func (t *typeOrigin) Doc() *ast.CommentGroup {
return t.doc
}
func (t *typeOrigin) Comment() *ast.CommentGroup {
return t.comment
}