mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
go/tools/cmd/godex: don't print unexported methods
and print exported methods of unexported types LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/80920046
This commit is contained in:
parent
33f2a1701b
commit
f293460f67
@ -55,23 +55,22 @@ func (p *printer) printPackage(pkg *types.Package, filter func(types.Object) boo
|
|||||||
var (
|
var (
|
||||||
consts []*types.Const
|
consts []*types.Const
|
||||||
typez []*types.TypeName // types without methods
|
typez []*types.TypeName // types without methods
|
||||||
typem []*types.TypeName // types with methods
|
typem []*types.Named // types with methods
|
||||||
vars []*types.Var
|
vars []*types.Var
|
||||||
funcs []*types.Func
|
funcs []*types.Func
|
||||||
builtins []*types.Builtin
|
builtins []*types.Builtin
|
||||||
)
|
)
|
||||||
scope := pkg.Scope()
|
scope := pkg.Scope()
|
||||||
for _, name := range scope.Names() {
|
for _, name := range scope.Names() {
|
||||||
obj := scope.Lookup(name)
|
if obj := scope.Lookup(name); filter(obj) {
|
||||||
if !filter(obj) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch obj := obj.(type) {
|
switch obj := obj.(type) {
|
||||||
case *types.Const:
|
case *types.Const:
|
||||||
consts = append(consts, obj)
|
consts = append(consts, obj)
|
||||||
case *types.TypeName:
|
case *types.TypeName:
|
||||||
|
// group into types with methods and types without
|
||||||
|
// (for now this is only considering explicitly declared - not "inherited" methods)
|
||||||
if named, _ := obj.Type().(*types.Named); named != nil && named.NumMethods() > 0 {
|
if named, _ := obj.Type().(*types.Named); named != nil && named.NumMethods() > 0 {
|
||||||
typem = append(typem, obj)
|
typem = append(typem, named)
|
||||||
} else {
|
} else {
|
||||||
typez = append(typez, obj)
|
typez = append(typez, obj)
|
||||||
}
|
}
|
||||||
@ -83,6 +82,15 @@ func (p *printer) printPackage(pkg *types.Package, filter func(types.Object) boo
|
|||||||
// for unsafe.Sizeof, etc.
|
// for unsafe.Sizeof, etc.
|
||||||
builtins = append(builtins, obj)
|
builtins = append(builtins, obj)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// type is filtered out but may contain visible methods
|
||||||
|
if obj, _ := obj.(*types.TypeName); obj != nil {
|
||||||
|
// see case *types.TypeName above
|
||||||
|
if named, _ := obj.Type().(*types.Named); named != nil && named.NumMethods() > 0 {
|
||||||
|
typem = append(typem, named)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printf("package %s // %q\n\n", pkg.Name(), pkg.Path())
|
p.printf("package %s // %q\n\n", pkg.Name(), pkg.Path())
|
||||||
@ -121,16 +129,24 @@ func (p *printer) printPackage(pkg *types.Package, filter func(types.Object) boo
|
|||||||
p.print(")\n\n")
|
p.print(")\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, obj := range typem {
|
for _, typ := range typem {
|
||||||
|
hasEntries := false
|
||||||
|
if obj := typ.Obj(); filter(obj) {
|
||||||
p.printf("type %s ", obj.Name())
|
p.printf("type %s ", obj.Name())
|
||||||
typ := obj.Type().(*types.Named)
|
|
||||||
p.writeType(p.pkg, typ.Underlying())
|
p.writeType(p.pkg, typ.Underlying())
|
||||||
p.print("\n")
|
p.print("\n")
|
||||||
|
hasEntries = true
|
||||||
|
}
|
||||||
for i, n := 0, typ.NumMethods(); i < n; i++ {
|
for i, n := 0, typ.NumMethods(); i < n; i++ {
|
||||||
p.printFunc(typ.Method(i))
|
if obj := typ.Method(i); filter(obj) {
|
||||||
|
p.printFunc(obj)
|
||||||
|
p.print("\n")
|
||||||
|
hasEntries = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasEntries {
|
||||||
p.print("\n")
|
p.print("\n")
|
||||||
}
|
}
|
||||||
p.print("\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, obj := range funcs {
|
for _, obj := range funcs {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user