diff options
| author | Rob Pike <r@golang.org> | 2015-06-02 14:43:38 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2015-06-04 21:51:49 +0000 |
| commit | ea92f42cc8b36511501644ff0512934619e16cf1 (patch) | |
| tree | a983413d31a8b7030e947e1f8594cf9f8a6c5f8d /src/cmd/doc | |
| parent | a7d2d4835b8dab9b1be6a3f772bb74d22fe9f312 (diff) | |
| download | go-ea92f42cc8b36511501644ff0512934619e16cf1.tar.xz | |
cmd/doc: do not show unexported constants
The go/doc package doesn't remove unexported entries from const
and var blocks, so we must trim them ourselves.
Fixes #11008
Change-Id: Ibd60d87e09333964e2588340a2ca2b8804bbaa28
Reviewed-on: https://go-review.googlesource.com/10643
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/doc')
| -rw-r--r-- | src/cmd/doc/pkg.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go index 5c8976b663..17ee8cee4f 100644 --- a/src/cmd/doc/pkg.go +++ b/src/cmd/doc/pkg.go @@ -332,6 +332,25 @@ func (pkg *Package) symbolDoc(symbol string) { values := pkg.findValues(symbol, pkg.doc.Consts) values = append(values, pkg.findValues(symbol, pkg.doc.Vars)...) for _, value := range values { + // Print each spec only if there is at least one exported symbol in it. + // (See issue 11008.) + // TODO: Should we elide unexported symbols from a single spec? + // It's an unlikely scenario, probably not worth the trouble. + // TODO: Would be nice if go/doc did this for us. + specs := make([]ast.Spec, 0, len(value.Decl.Specs)) + for _, spec := range value.Decl.Specs { + vspec := spec.(*ast.ValueSpec) + for _, ident := range vspec.Names { + if isExported(ident.Name) { + specs = append(specs, vspec) + break + } + } + } + if len(specs) == 0 { + continue + } + value.Decl.Specs = specs if !found { pkg.packageClause(true) } |
