poc: add type

上级 626dc59f
......@@ -6,6 +6,7 @@ import (
"go/parser"
"go/token"
"io/ioutil"
"reflect"
)
type WalkFunc func(ast.Node) (ast.Node, bool)
......@@ -19,14 +20,27 @@ func ProcessFile(fileName string) {
panic(err)
}
Visitor(f, fset)
}
func Visitor(f *ast.File, fset *token.FileSet) {
ast.Inspect(f, func(n ast.Node) bool {
var s string
switch x := n.(type) {
case *ast.File:
//packageName := x.Name
case *ast.Ident:
s = x.Name
case *ast.TypeSpec:
fmt.Println(x.Name)
case *ast.StructType:
fmt.Println(reflect.TypeOf(x))
for _, field := range x.Fields.List {
fmt.Println(field.Names, field.Type)
}
}
if s != "" {
fmt.Printf("%s:\t%s\n", fset.Position(n.Pos()), s)
//fmt.Printf("%s:\t%s\n", fset.Position(n.Pos()), s)
}
return true
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册