本文整理汇总了Golang中golang.org/x/tools/go/types.PkgName.Pkg方法的典型用法代码示例。如果您正苦于以下问题:Golang PkgName.Pkg方法的具体用法?Golang PkgName.Pkg怎么用?Golang PkgName.Pkg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/tools/go/types.PkgName
的用法示例。
在下文中一共展示了PkgName.Pkg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkInFileBlock
// checkInFileBlock performs safety checks for renames of objects in the file block,
// i.e. imported package names.
func (r *Unexporter) checkInFileBlock(objsToUpdate map[types.Object]string, from *types.PkgName, to string) {
// Check import name is not "init".
if to == "init" {
r.errorf(from.Pos(), "%q is not a valid imported package name", to)
}
// Check for conflicts between file and package block.
if prev := from.Pkg().Scope().Lookup(to); prev != nil {
r.warn(from,
r.errorf(from.Pos(), "renaming this %s %q to %q would conflict",
objectKind(from), from.Name(), to),
r.errorf(prev.Pos(), "\twith this package member %s",
objectKind(prev)))
return // since checkInPackageBlock would report redundant errors
}
// Check for conflicts in lexical scope.
r.checkInLexicalScope(objsToUpdate, from, to, r.packages[from.Pkg()])
// Finally, modify ImportSpec syntax to add or remove the Name as needed.
info, path, _ := r.iprog.PathEnclosingInterval(from.Pos(), from.Pos())
if from.Imported().Name() == to {
// ImportSpec.Name not needed
path[1].(*ast.ImportSpec).Name = nil
} else {
// ImportSpec.Name needed
if spec := path[1].(*ast.ImportSpec); spec.Name == nil {
spec.Name = &ast.Ident{NamePos: spec.Path.Pos(), Name: to}
info.Defs[spec.Name] = from
}
}
}