1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:44:44 -07:00

go.tools/go/types: SelectionString: print method with selective package-qualification.

R=gri, gri
CC=golang-dev
https://golang.org/cl/26570048
This commit is contained in:
Alan Donovan 2013-11-15 12:35:03 -05:00
parent f488a2c4f5
commit 45992044b5

View File

@ -116,22 +116,31 @@ func (s *Selection) Index() []int { return s.index }
// The result is false if x.f is a qualified identifier (PackageObj).
func (s *Selection) Indirect() bool { return s.indirect }
func (s *Selection) String() string {
func (s *Selection) String() string { return SelectionString(nil, s) }
// SelectionString returns the string form of s.
// Type names are printed package-qualified
// only if they do not belong to this package.
//
func SelectionString(this *Package, s *Selection) string {
var k string
switch s.kind {
case FieldVal:
k = "field"
k = "field "
case MethodVal:
k = "method"
k = "method "
case MethodExpr:
k = "method expr"
k = "method expr "
case PackageObj:
return fmt.Sprintf("qualified ident %s", s.obj)
default:
unreachable()
}
var buf bytes.Buffer
fmt.Fprintf(&buf, "%s (%s) %s", k, s.Recv(), s.obj.Name())
writeSignature(&buf, nil, s.Type().(*Signature))
buf.WriteString(k)
buf.WriteByte('(')
writeType(&buf, this, s.Recv())
fmt.Fprintf(&buf, ") %s", s.obj.Name())
writeSignature(&buf, this, s.Type().(*Signature))
return buf.String()
}