func (c *converter) convertScope(dst *types.Scope, src *gotypes.Scope) { for _, name := range src.Names() { obj := src.Lookup(name) dst.Insert(c.convertObject(obj)) } for i := 0; i < src.NumChildren(); i++ { child := src.Child(i) newScope := types.NewScope(dst, token.Pos(child.Pos()), token.Pos(child.End()), "") c.convertScope(newScope, child) } }
func (c *Suggester) scopeCandidates(scope *types.Scope, pos token.Pos, b *candidateCollector) { seen := make(map[string]bool) for scope != nil { isPkgScope := scope.Parent() == types.Universe for _, name := range scope.Names() { if seen[name] { continue } obj := scope.Lookup(name) if !isPkgScope && obj.Pos() > pos { continue } seen[name] = true b.appendObject(obj) } scope = scope.Parent() } }
func extractTestFunctions(scope *types.Scope) []string { var tests []string for _, name := range scope.Names() { if !strings.HasPrefix(name, "Test") { continue } if f, ok := scope.Lookup(name).(*types.Func); ok { sig := f.Type().(*types.Signature) // basic signature checks if sig.Recv() != nil { log.Printf("Skipping %q - test function should not be a method", f.String()) continue } if sig.Variadic() { log.Printf("Skipping %q - test function should not be variadic", f.String()) continue } if sig.Results() != nil { log.Printf("Skipping %q - test function should not return result", f.String()) continue } // check params params := sig.Params() if params != nil || params.Len() == 1 { if named, ok := params.At(0).Type().(*types.Named); ok { if named.Obj().Name() == "TestingT" { tests = append(tests, f.Name()) continue } } } log.Printf("Skipping %q - test function should have one parameter of type gophers.TestingT", f.String()) } } return tests }