本文整理汇总了Golang中go/types.Package.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Package.Name方法的具体用法?Golang Package.Name怎么用?Golang Package.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Package
的用法示例。
在下文中一共展示了Package.Name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: pkgPrefix
// pkgPrefix returns a prefix that disambiguates symbol names for binding
// multiple packages.
//
// TODO(elias.naur): Avoid (and test) name clashes from multiple packages
// with the same name. Perhaps use the index from the order the package is
// generated.
func pkgPrefix(pkg *types.Package) string {
// The error type has no package
if pkg == nil {
return ""
}
return pkg.Name()
}
示例2: GenGo
func (b *binder) GenGo(pkg *types.Package, allPkg []*types.Package, outdir string) error {
pkgName := "go_"
pkgPath := ""
if pkg != nil {
pkgName += pkg.Name()
pkgPath = pkg.Path()
}
goFile := filepath.Join(outdir, pkgName+"main.go")
generate := func(w io.Writer) error {
if buildX {
printcmd("gobind -lang=go -outdir=%s %s", outdir, pkgPath)
}
if buildN {
return nil
}
conf := &bind.GeneratorConfig{
Writer: w,
Fset: b.fset,
Pkg: pkg,
AllPkg: allPkg,
}
return bind.GenGo(conf)
}
if err := writeFile(goFile, generate); err != nil {
return err
}
return nil
}
示例3: find
func find(pkg *types.Package, iface string) (*types.Interface, error) {
scope := pkg.Scope()
names := scope.Names()
for _, n := range names {
obj := scope.Lookup(n)
tn, ok := obj.(*types.TypeName)
if !ok {
continue
}
if tn.Name() != iface {
continue
}
if !obj.Exported() {
return nil, fmt.Errorf("%s should exported", iface)
}
t := tn.Type().Underlying()
i, ok := t.(*types.Interface)
if !ok {
return nil, fmt.Errorf("exptected interface, got %s for %s", t, iface)
}
return i, nil
}
return nil, fmt.Errorf("%s not found in %s", iface, pkg.Name())
}
示例4: Qualifier
func (p *Parser) Qualifier(pkg *types.Package) string {
if pkg.Name() == p.Package {
return ""
}
return pkg.Name()
}
示例5: Collect
//Collect going through package and collect info
//using conf.Check method. It's using this implementation
//of importer for check all inner packages and go/types/importer.Default()
//to check all built in packages (without sources)
func (_importer *CollectInfoImporter) Collect() (*types.Package, *token.FileSet, error) {
var conf types.Config
conf.Importer = _importer
conf.Error = _importer.errorHandler
if _importer.packages == nil {
_importer.packages = make(map[string]*types.Package)
}
var pkg *types.Package
var err error
var files []string
if files, err = fs.SourceFiles(_importer.Pkg, false); err != nil {
return nil, nil, err
}
if _importer.fset, _importer.astFiles, err = doParseFiles(files, _importer.fset); err != nil {
return nil, nil, err
}
//XXX: return positive result if check() returns error.
pkg, _ = conf.Check(_importer.Pkg, _importer.fset, _importer.astFiles, _importer.Info)
// if pkg, err = conf.Check(_importer.Pkg, _importer.fset, _importer.astFiles, _importer.Info); err != nil {
// return pkg, _importer.fset, err
// }
_importer.packages[_importer.Pkg] = pkg
util.Debug("package [%s] successfully parsed\n", pkg.Name())
return pkg, _importer.fset, nil
}
示例6: convertPackage
func (c *converter) convertPackage(v *gotypes.Package) *types.Package {
if v == nil {
return nil
}
if v, ok := c.converted[v]; ok {
return v.(*types.Package)
}
ret := types.NewPackage(v.Path(), v.Name())
if c.ret == nil {
c.ret = ret
}
c.converted[v] = ret
var imports []*types.Package
for _, imported := range v.Imports() {
imports = append(imports, c.convertPackage(imported))
}
ret.SetImports(imports)
c.convertScope(ret.Scope(), v.Scope())
for _, iface := range c.ifaces {
iface.Complete()
}
return ret
}
示例7: defaultFileName
func defaultFileName(lang string, pkg *types.Package) string {
switch lang {
case "java":
if pkg == nil {
return "Universe.java"
}
firstRune, size := utf8.DecodeRuneInString(pkg.Name())
className := string(unicode.ToUpper(firstRune)) + pkg.Name()[size:]
return className + ".java"
case "go":
if pkg == nil {
return "go_universe.go"
}
return "go_" + pkg.Name() + ".go"
case "objc":
if pkg == nil {
return "GoUniverse.m"
}
firstRune, size := utf8.DecodeRuneInString(pkg.Name())
className := string(unicode.ToUpper(firstRune)) + pkg.Name()[size:]
return "Go" + className + ".m"
}
errorf("unknown target language: %q", lang)
os.Exit(exitStatus)
return ""
}
示例8: namePrefixOf
func (g *objcGen) namePrefixOf(pkg *types.Package) string {
p := g.prefix
if p == "" {
p = "Go"
}
return p + strings.Title(pkg.Name())
}
示例9: pkg
func (p *exporter) pkg(pkg *types.Package, emptypath bool) {
if pkg == nil {
log.Fatalf("gcimporter: unexpected nil pkg")
}
// if we saw the package before, write its index (>= 0)
if i, ok := p.pkgIndex[pkg]; ok {
p.index('P', i)
return
}
// otherwise, remember the package, write the package tag (< 0) and package data
if trace {
p.tracef("P%d = { ", len(p.pkgIndex))
defer p.tracef("} ")
}
p.pkgIndex[pkg] = len(p.pkgIndex)
p.tag(packageTag)
p.string(pkg.Name())
if emptypath {
p.string("")
} else {
p.string(pkg.Path())
}
}
示例10: pkgName
// pkgName retuns the package name and adds the package to the list of
// imports.
func (g *goGen) pkgName(pkg *types.Package) string {
// The error type has no package
if pkg == nil {
return ""
}
g.imports[pkg.Path()] = struct{}{}
return pkg.Name() + "."
}
示例11: GenObjc
func (b *binder) GenObjc(pkg *types.Package, allPkg []*types.Package, outdir string) (string, error) {
const bindPrefixDefault = "Go"
if bindPrefix == "" {
bindPrefix = bindPrefixDefault
}
name := strings.Title(pkg.Name())
bindOption := "-lang=objc"
if bindPrefix != bindPrefixDefault {
bindOption += " -prefix=" + bindPrefix
}
fileBase := bindPrefix + name
mfile := filepath.Join(outdir, fileBase+".m")
hfile := filepath.Join(outdir, fileBase+".h")
gohfile := filepath.Join(outdir, pkg.Name()+".h")
conf := &bind.GeneratorConfig{
Fset: b.fset,
Pkg: pkg,
AllPkg: allPkg,
}
generate := func(w io.Writer) error {
if buildX {
printcmd("gobind %s -outdir=%s %s", bindOption, outdir, pkg.Path())
}
if buildN {
return nil
}
conf.Writer = w
return bind.GenObjc(conf, bindPrefix, bind.ObjcM)
}
if err := writeFile(mfile, generate); err != nil {
return "", err
}
generate = func(w io.Writer) error {
if buildN {
return nil
}
conf.Writer = w
return bind.GenObjc(conf, bindPrefix, bind.ObjcH)
}
if err := writeFile(hfile, generate); err != nil {
return "", err
}
generate = func(w io.Writer) error {
if buildN {
return nil
}
conf.Writer = w
return bind.GenObjc(conf, bindPrefix, bind.ObjcGoH)
}
if err := writeFile(gohfile, generate); err != nil {
return "", err
}
return fileBase, nil
}
示例12: namePrefixOf
func (g *ObjcGen) namePrefixOf(pkg *types.Package) string {
if pkg == nil {
return "GoUniverse"
}
p := g.Prefix
if p == "" {
p = "Go"
}
return p + strings.Title(pkg.Name())
}
示例13: joinQuery
func joinQuery(pkg *types.Package, parent types.Object, obj types.Object, suffix string) string {
var args []string
args = append(args, pkg.Name())
if parent != nil {
args = append(args, parent.Name())
}
args = append(args, nameExported(obj.Name()))
return strings.Join(args, ".") + suffix
}
示例14: newBinder
func newBinder(p *types.Package) (*binder, error) {
if p.Name() == "main" {
return nil, fmt.Errorf("package %q: can only bind a library package", p.Name())
}
b := &binder{
fset: token.NewFileSet(),
pkg: p,
}
return b, nil
}
示例15: JavaPkgName
// JavaPkgName returns the Java package name for a Go package
// given a pkg prefix. If the prefix is empty, "go" is used
// instead.
func JavaPkgName(pkgPrefix string, pkg *types.Package) string {
if pkg == nil {
return "go"
}
s := javaNameReplacer(pkg.Name())
if pkgPrefix != "" {
return pkgPrefix + "." + s
} else {
return "go." + s
}
}