forked from goplus/gop
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelper.gop
50 lines (48 loc) · 836 Bytes
/
helper.gop
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
import (
"go/ast"
)
func importSpec(path string) *ast.ImportSpec {
return {
Path: {
Value: path.quote,
},
}
}
func toParams(params *ast.FieldList, at string) *ast.FieldList {
if params == nil {
return nil
}
if at == "buil" {
at = "builtin"
}
list := make([]*ast.Field, len(params.List))
for i, p <- params.List {
typ := p.Type
switch t := typ.(type) {
case *ast.Ident:
if t.isExported {
typ = &ast.SelectorExpr{
X: ast.newIdent(at),
Sel: t,
}
}
case *ast.StarExpr:
if x, ok := t.X.(*ast.Ident); ok && x.isExported {
typ = &ast.StarExpr{
X: &ast.SelectorExpr{
X: ast.newIdent(at),
Sel: x,
},
}
}
}
list[i] = {
Doc: p.Doc,
Names: p.Names,
Type: typ,
Tag: p.Tag,
Comment: p.Comment,
}
}
return {List: list}
}