1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:04:52 -07:00

go.tools/oracle: use SelectionString when printing methods.

R=gri, crawshaw, gri
CC=golang-dev
https://golang.org/cl/26900043
This commit is contained in:
Alan Donovan 2013-11-15 12:35:11 -05:00
parent 45992044b5
commit 9c112540f6
4 changed files with 22 additions and 17 deletions

View File

@ -670,7 +670,7 @@ func (r *describeTypeResult) display(printf printfFunc) {
if len(r.methods) > 0 {
printf(r.node, "Method set:")
for _, meth := range r.methods {
printf(meth.Obj(), "\t%s", meth)
printf(meth.Obj(), "\t%s", r.qpos.SelectionString(meth))
}
} else {
printf(r.node, "No methods.")
@ -692,7 +692,7 @@ func (r *describeTypeResult) toSerial(res *serial.Result, fset *token.FileSet) {
Type: r.qpos.TypeString(r.typ),
NamePos: namePos,
NameDef: nameDef,
Methods: methodsToSerial(r.methods, fset),
Methods: methodsToSerial(r.qpos.info.Pkg, r.methods, fset),
},
}
}
@ -790,10 +790,10 @@ func formatMember(obj types.Object, maxname int) string {
fmt.Fprintf(&buf, "%-5s %-*s", tokenOf(obj), maxname, obj.Name())
switch obj := obj.(type) {
case *types.Const:
fmt.Fprintf(&buf, " %s = %s", obj.Type(), obj.Val().String())
fmt.Fprintf(&buf, " %s = %s", types.TypeString(obj.Pkg(), obj.Type()), obj.Val().String())
case *types.Func:
fmt.Fprintf(&buf, " %s", obj.Type())
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Pkg(), obj.Type()))
case *types.TypeName:
// Abbreviate long aggregate type names.
@ -809,13 +809,13 @@ func formatMember(obj types.Object, maxname int) string {
}
}
if abbrev == "" {
fmt.Fprintf(&buf, " %s", obj.Type().Underlying())
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Pkg(), obj.Type().Underlying()))
} else {
fmt.Fprintf(&buf, " %s", abbrev)
}
case *types.Var:
fmt.Fprintf(&buf, " %s", obj.Type())
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Pkg(), obj.Type()))
}
return buf.String()
}
@ -837,7 +837,7 @@ func (r *describePackageResult) toSerial(res *serial.Result, fset *token.FileSet
Value: val,
Pos: fset.Position(mem.obj.Pos()).String(),
Kind: tokenOf(mem.obj),
Methods: methodsToSerial(mem.methods, fset),
Methods: methodsToSerial(r.pkg, mem.methods, fset),
})
}
res.Describe = &serial.Describe{
@ -935,11 +935,11 @@ func isAccessibleFrom(obj types.Object, pkg *types.Package) bool {
return ast.IsExported(obj.Name()) || obj.Pkg() == pkg
}
func methodsToSerial(methods []*types.Selection, fset *token.FileSet) []serial.DescribeMethod {
func methodsToSerial(this *types.Package, methods []*types.Selection, fset *token.FileSet) []serial.DescribeMethod {
var jmethods []serial.DescribeMethod
for _, meth := range methods {
jmethods = append(jmethods, serial.DescribeMethod{
Name: meth.String(),
Name: types.SelectionString(this, meth),
Pos: fset.Position(meth.Obj().Pos()).String(),
})
}

View File

@ -120,6 +120,11 @@ func (qpos *QueryPos) ObjectString(obj types.Object) string {
return types.ObjectString(qpos.info.Pkg, obj)
}
// SelectionString prints selection sel relative to the query position.
func (qpos *QueryPos) SelectionString(sel *types.Selection) string {
return types.SelectionString(qpos.info.Pkg, sel)
}
// A Result encapsulates the result of an oracle.Query.
type Result struct {
fset *token.FileSet

View File

@ -15,7 +15,7 @@
"kind": "type",
"methods": [
{
"name": "method (describe.C) f()",
"name": "method (C) f()",
"pos": "testdata/src/main/describe-json.go:30:12"
}
]
@ -27,7 +27,7 @@
"kind": "type",
"methods": [
{
"name": "method (*describe.D) f()",
"name": "method (*D) f()",
"pos": "testdata/src/main/describe-json.go:31:13"
}
]
@ -39,7 +39,7 @@
"kind": "type",
"methods": [
{
"name": "method (describe.I) f()",
"name": "method (I) f()",
"pos": "testdata/src/main/describe-json.go:24:2"
}
]
@ -142,7 +142,7 @@
"namedef": "int",
"methods": [
{
"name": "method (describe.C) f()",
"name": "method (C) f()",
"pos": "testdata/src/main/describe-json.go:30:12"
}
]

View File

@ -12,7 +12,7 @@ definition of package "describe"
var global *string
func main func()
const pi untyped float = 3141/1000
const pie describe.cake = 1768225803696341/562949953421312
const pie cake = 1768225803696341/562949953421312
-------- @describe type-ref-builtin --------
reference to built-in type float64
@ -53,13 +53,13 @@ defined here
reference to type D
defined as struct{}
Method set:
method (describe.D) f()
method (D) f()
-------- @describe type-I --------
reference to type I
defined as interface{f()}
Method set:
method (describe.I) f()
method (I) f()
-------- @describe func-ref-d.f --------
reference to method func (D).f()
@ -188,7 +188,7 @@ no points-to information: PTA did not encounter this expression (dead code?)
-------- @describe def-iface-I --------
definition of type I
Method set:
method (describe.I) f()
method (I) f()
-------- @describe def-imethod-I.f --------
type interface{f()}