process collects informations about a go package.
()
| 294 | |
| 295 | // process collects informations about a go package. |
| 296 | func (p *Package) process() error { |
| 297 | var err error |
| 298 | |
| 299 | p.syms.pkg = p.pkg |
| 300 | p.syms.addImport(p.pkg) |
| 301 | |
| 302 | funcs := make(map[string]*Func) |
| 303 | structs := make(map[string]*Struct) |
| 304 | ifaces := make(map[string]*Interface) |
| 305 | slices := make(map[string]*Slice) |
| 306 | maps := make(map[string]*Map) |
| 307 | |
| 308 | scope := p.pkg.Scope() |
| 309 | for _, name := range scope.Names() { |
| 310 | obj := scope.Lookup(name) |
| 311 | if !obj.Exported() { |
| 312 | continue |
| 313 | } |
| 314 | |
| 315 | p.n++ |
| 316 | p.syms.addSymbol(obj) |
| 317 | } |
| 318 | |
| 319 | for _, name := range scope.Names() { |
| 320 | obj := scope.Lookup(name) |
| 321 | if !obj.Exported() { |
| 322 | continue |
| 323 | } |
| 324 | |
| 325 | switch obj := obj.(type) { |
| 326 | case *types.Const: |
| 327 | p.addConst(obj) |
| 328 | |
| 329 | case *types.Var: |
| 330 | p.addVar(obj) |
| 331 | |
| 332 | case *types.Func: |
| 333 | fv, err := newFuncFrom(p, "", obj, obj.Type().(*types.Signature)) |
| 334 | if err != nil { |
| 335 | continue |
| 336 | } |
| 337 | funcs[name] = fv |
| 338 | |
| 339 | case *types.TypeName: |
| 340 | typ := obj.Type() |
| 341 | if named, ok := typ.(*types.Named); ok { |
| 342 | typ = named.Underlying() |
| 343 | } else { |
| 344 | // we are dealing with a type alias to a type literal. |
| 345 | // this is a cursed feature used to do structural typing. |
| 346 | // just pass it as-is. |
| 347 | } |
| 348 | switch typ := typ.(type) { |
| 349 | case *types.Struct: |
| 350 | sv, err := newStruct(p, obj) |
| 351 | if err != nil { |
| 352 | fmt.Println(err) |
| 353 | continue |
no test coverage detected