本文整理汇总了Golang中go/types.Scope.Names方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.Names方法的具体用法?Golang Scope.Names怎么用?Golang Scope.Names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Scope
的用法示例。
在下文中一共展示了Scope.Names方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: convertScope
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)
}
}
示例2: scopeCandidates
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()
}
}
示例3: extractTestFunctions
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
}