in tools/go-agent/instrument/plugins/rewrite/type.go [29:64]
func (c *Context) Type(tp *dst.TypeSpec, parent dst.Node, onlyName bool) {
oldName := tp.Name.Name
if !c.alreadyGenerated(oldName) {
tp.Name = dst.NewIdent(fmt.Sprintf("%s%s%s", c.generateTypePrefix(parent), c.currentPackageTitle, oldName))
c.rewriteMapping.addTypeMapping(oldName, tp.Name.Name)
}
if onlyName {
return
}
// define interface type, ex: "type xxx interface {}"
if inter, ok := tp.Type.(*dst.InterfaceType); ok {
for _, method := range inter.Methods.List {
switch t := method.Type.(type) {
case *dst.Ident:
c.enhanceTypeNameWhenRewrite(t, tp.Type, -1)
case *dst.FuncType:
c.enhanceFuncParameter(t.Params)
c.enhanceFuncParameter(t.Results)
}
}
}
// define func type, ex: "type xxx func(x X) x"
if funcType, ok := tp.Type.(*dst.FuncType); ok {
c.enhanceFuncParameter(funcType.Params)
c.enhanceFuncParameter(funcType.Results)
}
// define struct type, ex: "type xx struct {}"
if structType, ok := tp.Type.(*dst.StructType); ok && structType.Fields != nil {
for _, field := range structType.Fields.List {
c.enhanceTypeNameWhenRewrite(field.Type, field, -1)
}
}
}