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:
parent
45992044b5
commit
9c112540f6
|
|
@ -670,7 +670,7 @@ func (r *describeTypeResult) display(printf printfFunc) {
|
||||||
if len(r.methods) > 0 {
|
if len(r.methods) > 0 {
|
||||||
printf(r.node, "Method set:")
|
printf(r.node, "Method set:")
|
||||||
for _, meth := range r.methods {
|
for _, meth := range r.methods {
|
||||||
printf(meth.Obj(), "\t%s", meth)
|
printf(meth.Obj(), "\t%s", r.qpos.SelectionString(meth))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf(r.node, "No methods.")
|
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),
|
Type: r.qpos.TypeString(r.typ),
|
||||||
NamePos: namePos,
|
NamePos: namePos,
|
||||||
NameDef: nameDef,
|
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())
|
fmt.Fprintf(&buf, "%-5s %-*s", tokenOf(obj), maxname, obj.Name())
|
||||||
switch obj := obj.(type) {
|
switch obj := obj.(type) {
|
||||||
case *types.Const:
|
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:
|
case *types.Func:
|
||||||
fmt.Fprintf(&buf, " %s", obj.Type())
|
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Pkg(), obj.Type()))
|
||||||
|
|
||||||
case *types.TypeName:
|
case *types.TypeName:
|
||||||
// Abbreviate long aggregate type names.
|
// Abbreviate long aggregate type names.
|
||||||
|
|
@ -809,13 +809,13 @@ func formatMember(obj types.Object, maxname int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if abbrev == "" {
|
if abbrev == "" {
|
||||||
fmt.Fprintf(&buf, " %s", obj.Type().Underlying())
|
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Pkg(), obj.Type().Underlying()))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(&buf, " %s", abbrev)
|
fmt.Fprintf(&buf, " %s", abbrev)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *types.Var:
|
case *types.Var:
|
||||||
fmt.Fprintf(&buf, " %s", obj.Type())
|
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Pkg(), obj.Type()))
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
@ -837,7 +837,7 @@ func (r *describePackageResult) toSerial(res *serial.Result, fset *token.FileSet
|
||||||
Value: val,
|
Value: val,
|
||||||
Pos: fset.Position(mem.obj.Pos()).String(),
|
Pos: fset.Position(mem.obj.Pos()).String(),
|
||||||
Kind: tokenOf(mem.obj),
|
Kind: tokenOf(mem.obj),
|
||||||
Methods: methodsToSerial(mem.methods, fset),
|
Methods: methodsToSerial(r.pkg, mem.methods, fset),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
res.Describe = &serial.Describe{
|
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
|
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
|
var jmethods []serial.DescribeMethod
|
||||||
for _, meth := range methods {
|
for _, meth := range methods {
|
||||||
jmethods = append(jmethods, serial.DescribeMethod{
|
jmethods = append(jmethods, serial.DescribeMethod{
|
||||||
Name: meth.String(),
|
Name: types.SelectionString(this, meth),
|
||||||
Pos: fset.Position(meth.Obj().Pos()).String(),
|
Pos: fset.Position(meth.Obj().Pos()).String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,11 @@ func (qpos *QueryPos) ObjectString(obj types.Object) string {
|
||||||
return types.ObjectString(qpos.info.Pkg, obj)
|
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.
|
// A Result encapsulates the result of an oracle.Query.
|
||||||
type Result struct {
|
type Result struct {
|
||||||
fset *token.FileSet
|
fset *token.FileSet
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
"kind": "type",
|
"kind": "type",
|
||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "method (describe.C) f()",
|
"name": "method (C) f()",
|
||||||
"pos": "testdata/src/main/describe-json.go:30:12"
|
"pos": "testdata/src/main/describe-json.go:30:12"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
"kind": "type",
|
"kind": "type",
|
||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "method (*describe.D) f()",
|
"name": "method (*D) f()",
|
||||||
"pos": "testdata/src/main/describe-json.go:31:13"
|
"pos": "testdata/src/main/describe-json.go:31:13"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
"kind": "type",
|
"kind": "type",
|
||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "method (describe.I) f()",
|
"name": "method (I) f()",
|
||||||
"pos": "testdata/src/main/describe-json.go:24:2"
|
"pos": "testdata/src/main/describe-json.go:24:2"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -142,7 +142,7 @@
|
||||||
"namedef": "int",
|
"namedef": "int",
|
||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "method (describe.C) f()",
|
"name": "method (C) f()",
|
||||||
"pos": "testdata/src/main/describe-json.go:30:12"
|
"pos": "testdata/src/main/describe-json.go:30:12"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ definition of package "describe"
|
||||||
var global *string
|
var global *string
|
||||||
func main func()
|
func main func()
|
||||||
const pi untyped float = 3141/1000
|
const pi untyped float = 3141/1000
|
||||||
const pie describe.cake = 1768225803696341/562949953421312
|
const pie cake = 1768225803696341/562949953421312
|
||||||
|
|
||||||
-------- @describe type-ref-builtin --------
|
-------- @describe type-ref-builtin --------
|
||||||
reference to built-in type float64
|
reference to built-in type float64
|
||||||
|
|
@ -53,13 +53,13 @@ defined here
|
||||||
reference to type D
|
reference to type D
|
||||||
defined as struct{}
|
defined as struct{}
|
||||||
Method set:
|
Method set:
|
||||||
method (describe.D) f()
|
method (D) f()
|
||||||
|
|
||||||
-------- @describe type-I --------
|
-------- @describe type-I --------
|
||||||
reference to type I
|
reference to type I
|
||||||
defined as interface{f()}
|
defined as interface{f()}
|
||||||
Method set:
|
Method set:
|
||||||
method (describe.I) f()
|
method (I) f()
|
||||||
|
|
||||||
-------- @describe func-ref-d.f --------
|
-------- @describe func-ref-d.f --------
|
||||||
reference to method func (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 --------
|
-------- @describe def-iface-I --------
|
||||||
definition of type I
|
definition of type I
|
||||||
Method set:
|
Method set:
|
||||||
method (describe.I) f()
|
method (I) f()
|
||||||
|
|
||||||
-------- @describe def-imethod-I.f --------
|
-------- @describe def-imethod-I.f --------
|
||||||
type interface{f()}
|
type interface{f()}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue