Skip to content

Commit a8a2d02

Browse files
committed
fixes
1 parent a89fda8 commit a8a2d02

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

types_origin.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,9 @@ import (
55
)
66

77
func newTypeOrigin(v Type, ori ast.Node, info *info, doc, comment *ast.CommentGroup) Type {
8-
pkg := info.PkgPath
9-
goroot := info.Goroot || v.IsGoroot()
10-
if p := v.PkgPath(); p != "" {
11-
pkg = p
12-
}
13-
if doc == nil {
14-
doc = v.Doc()
15-
}
16-
if comment == nil {
17-
comment = v.Comment()
18-
}
198
return &typeOrigin{
209
Type: v,
21-
pkgPath: pkg,
22-
goroot: goroot,
10+
info: info,
2311
ori: ori,
2412
doc: doc,
2513
comment: comment,
@@ -29,28 +17,42 @@ func newTypeOrigin(v Type, ori ast.Node, info *info, doc, comment *ast.CommentGr
2917
type typeOrigin struct {
3018
Type
3119
ori ast.Node
32-
pkgPath string
20+
info *info
3321
goroot bool
3422
doc *ast.CommentGroup
3523
comment *ast.CommentGroup
24+
pkgPath string
3625
}
3726

3827
func (t *typeOrigin) Origin() ast.Node {
3928
return t.ori
4029
}
4130

4231
func (t *typeOrigin) PkgPath() string {
32+
if t.pkgPath != "" {
33+
return t.pkgPath
34+
}
35+
t.pkgPath = t.Type.PkgPath()
36+
if t.pkgPath == "" {
37+
t.pkgPath = t.info.PkgPath
38+
}
4339
return t.pkgPath
4440
}
4541

4642
func (t *typeOrigin) IsGoroot() bool {
47-
return t.goroot
43+
return t.info.Goroot || t.Type.IsGoroot()
4844
}
4945

5046
func (t *typeOrigin) Doc() *ast.CommentGroup {
51-
return t.doc
47+
if t.doc != nil {
48+
return t.doc
49+
}
50+
return t.Type.Doc()
5251
}
5352

5453
func (t *typeOrigin) Comment() *ast.CommentGroup {
55-
return t.comment
54+
if t.comment != nil {
55+
return t.comment
56+
}
57+
return t.Type.Comment()
5658
}

0 commit comments

Comments
 (0)