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:
parent
f488a2c4f5
commit
45992044b5
|
|
@ -116,22 +116,31 @@ func (s *Selection) Index() []int { return s.index }
|
||||||
// The result is false if x.f is a qualified identifier (PackageObj).
|
// The result is false if x.f is a qualified identifier (PackageObj).
|
||||||
func (s *Selection) Indirect() bool { return s.indirect }
|
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
|
var k string
|
||||||
switch s.kind {
|
switch s.kind {
|
||||||
case FieldVal:
|
case FieldVal:
|
||||||
k = "field"
|
k = "field "
|
||||||
case MethodVal:
|
case MethodVal:
|
||||||
k = "method"
|
k = "method "
|
||||||
case MethodExpr:
|
case MethodExpr:
|
||||||
k = "method expr"
|
k = "method expr "
|
||||||
case PackageObj:
|
case PackageObj:
|
||||||
return fmt.Sprintf("qualified ident %s", s.obj)
|
return fmt.Sprintf("qualified ident %s", s.obj)
|
||||||
default:
|
default:
|
||||||
unreachable()
|
unreachable()
|
||||||
}
|
}
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
fmt.Fprintf(&buf, "%s (%s) %s", k, s.Recv(), s.obj.Name())
|
buf.WriteString(k)
|
||||||
writeSignature(&buf, nil, s.Type().(*Signature))
|
buf.WriteByte('(')
|
||||||
|
writeType(&buf, this, s.Recv())
|
||||||
|
fmt.Fprintf(&buf, ") %s", s.obj.Name())
|
||||||
|
writeSignature(&buf, this, s.Type().(*Signature))
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue