本文整理汇总了Golang中golang.org/x/tools/go/types.Object.Imported方法的典型用法代码示例。如果您正苦于以下问题:Golang Object.Imported方法的具体用法?Golang Object.Imported怎么用?Golang Object.Imported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/tools/go/types.Object
的用法示例。
在下文中一共展示了Object.Imported方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sameObj
// same reports whether x and y are identical, or both are PkgNames
// that import the same Package.
//
func sameObj(x, y types.Object) bool {
if x == y {
return true
}
if x, ok := x.(*types.PkgName); ok {
if y, ok := y.(*types.PkgName); ok {
return x.Imported() == y.Imported()
}
}
return false
}
示例2: makeDefInfo
func (g *Grapher) makeDefInfo(obj types.Object) (*DefKey, *defInfo, error) {
switch obj := obj.(type) {
case *types.Builtin:
return &DefKey{"builtin", []string{obj.Name()}}, &defInfo{pkgscope: false, exported: true}, nil
case *types.Nil:
return &DefKey{"builtin", []string{"nil"}}, &defInfo{pkgscope: false, exported: true}, nil
case *types.TypeName:
if basic, ok := obj.Type().(*types.Basic); ok {
return &DefKey{"builtin", []string{basic.Name()}}, &defInfo{pkgscope: false, exported: true}, nil
}
if obj.Name() == "error" {
return &DefKey{"builtin", []string{obj.Name()}}, &defInfo{pkgscope: false, exported: true}, nil
}
case *types.PkgName:
return &DefKey{obj.Imported().Path(), []string{}}, &defInfo{pkgscope: false, exported: true}, nil
case *types.Const:
var pkg string
if obj.Pkg() == nil {
pkg = "builtin"
} else {
pkg = obj.Pkg().Path()
}
if obj.Val().Kind() == exact.Bool && pkg == "builtin" {
return &DefKey{pkg, []string{obj.Name()}}, &defInfo{pkgscope: false, exported: true}, nil
}
}
if obj.Pkg() == nil {
// builtin
return &DefKey{"builtin", []string{obj.Name()}}, &defInfo{pkgscope: false, exported: true}, nil
}
path := g.path(obj)
// Handle the case where a dir has 2 main packages that are not
// intended to be compiled together and have overlapping def
// paths. Prefix the def path with the filename.
if obj.Pkg().Name() == "main" {
p := g.program.Fset.Position(obj.Pos())
path = append([]string{filepath.Base(p.Filename)}, path...)
}
return &DefKey{obj.Pkg().Path(), path}, &defInfo{pkgscope: g.pkgscope[obj], exported: g.exported[obj]}, nil
}