mirror of
https://github.com/golang/go
synced 2024-11-19 02:54:42 -07: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:
parent
677415b351
commit
3f686cae84
@ -23,7 +23,7 @@ func pkgFor(path, source string, info *Info) (*Package, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var conf Config
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,17 @@ func writeType(buf *bytes.Buffer, typ Type) {
|
|||||||
// if we are referring to a type that was imported;
|
// if we are referring to a type that was imported;
|
||||||
// but not when we are at the "top". We don't have
|
// but not when we are at the "top". We don't have
|
||||||
// this information easily available here.
|
// 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('.')
|
buf.WriteByte('.')
|
||||||
}
|
}
|
||||||
s = t.obj.name
|
s = t.obj.name
|
||||||
|
Loading…
Reference in New Issue
Block a user