1
0
mirror of https://github.com/golang/go synced 2024-10-01 09:38:36 -06:00

go.tools/go/types: print named types with package qualification.

Depending on the context, printing only the package name can
be ambiguous or even incorrect since it is valid only within
the environment of a given file's import specs.

(The standard library packages are mostly unique in their last
segment, but this is not the case for proprietary repos.)

R=gri, gri
CC=golang-dev
https://golang.org/cl/26300043
This commit is contained in:
Alan Donovan 2013-11-13 16:03:41 -05:00
parent 677415b351
commit 3f686cae84
2 changed files with 12 additions and 2 deletions

View File

@ -23,7 +23,7 @@ func pkgFor(path, source string, info *Info) (*Package, error) {
}
var conf Config
pkg, err := conf.Check(path, fset, []*ast.File{f}, info)
pkg, err := conf.Check(f.Name.Name, fset, []*ast.File{f}, info)
if err != nil {
return nil, err
}

View File

@ -327,7 +327,17 @@ func writeType(buf *bytes.Buffer, typ Type) {
// if we are referring to a type that was imported;
// but not when we are at the "top". We don't have
// this information easily available here.
buf.WriteString(obj.pkg.name)
//
// TODO(gri): define variants of Type.String()
// and Object.String() that accept the referring *Package
// as a parameter and omit the package qualification for
// intra-package references to named types.
//
// Some applications may want another variant that accepts a
// file Scope and prints packages using that file's local
// import names. (Printing just pkg.name may be ambiguous
// or incorrect in other scopes.)
buf.WriteString(obj.pkg.path)
buf.WriteByte('.')
}
s = t.obj.name