aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2019-04-15 23:10:50 +0900
committerBrad Fitzpatrick <bradfitz@golang.org>2019-04-16 14:43:48 +0000
commit9b968df17782f21cc0af14c9d3c0bcf4cf3f911f (patch)
tree0240ff2603a12a7f9206b27967b8a60b992110cb /src/cmd/doc
parentb39d0eab902cb6b90aa99bcf11ca622c00219c7c (diff)
downloadgo-9b968df17782f21cc0af14c9d3c0bcf4cf3f911f.tar.gz
go-9b968df17782f21cc0af14c9d3c0bcf4cf3f911f.zip
all: clean up code with token.IsExported
A handful of packages were reimplementing IsExported, so use token.IsExported instead. This caused the deps test to fail for net/rpc. However, net/rpc deals with Go types, and go/token is light and fairly low-level in terms of Go tooling packages, so that's okay. While at it, replace all uses of ast.IsExported with token.IsExported. This is more consistent, and also means that the import graphs are leaner. A couple of files no longer need to import go/ast, for example. We can't get rid of cmd/compile/internal/types.IsExported, as the compiler can only depend on go/token as of Go 1.4. However, gc used different implementations in a couple of places, so consolidate the use of types.IsExported there. Finally, we can't get rid of the copied IsExported implementation in encoding/gob, as go/token depends on it as part of a test. That test can't be an external test either, so there's no easy way to break the import cycle. Overall, this removes about forty lines of unnecessary code. Change-Id: I86a475b7614261e6a7b0b153d5ca02b9f64a7b2d Reviewed-on: https://go-review.googlesource.com/c/go/+/172037 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/doc')
-rw-r--r--src/cmd/doc/main.go14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/cmd/doc/main.go b/src/cmd/doc/main.go
index 9b24c5874f..9e3ad0c0e7 100644
--- a/src/cmd/doc/main.go
+++ b/src/cmd/doc/main.go
@@ -49,8 +49,6 @@ import (
"path"
"path/filepath"
"strings"
- "unicode"
- "unicode/utf8"
)
var (
@@ -235,7 +233,7 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo
// case letter, it can only be a symbol in the current directory.
// Kills the problem caused by case-insensitive file systems
// matching an upper case name as a package name.
- if isUpper(arg) {
+ if token.IsExported(arg) {
pkg, err := build.ImportDir(".", build.ImportComment)
if err == nil {
return pkg, "", arg, false
@@ -352,19 +350,13 @@ func parseSymbol(str string) (symbol, method string) {
// If the unexported flag (-u) is true, isExported returns true because
// it means that we treat the name as if it is exported.
func isExported(name string) bool {
- return unexported || isUpper(name)
-}
-
-// isUpper reports whether the name starts with an upper case letter.
-func isUpper(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
+ return unexported || token.IsExported(name)
}
// findNextPackage returns the next full file name path that matches the
// (perhaps partial) package path pkg. The boolean reports if any match was found.
func findNextPackage(pkg string) (string, bool) {
- if pkg == "" || isUpper(pkg) { // Upper case symbol cannot be a package name.
+ if pkg == "" || token.IsExported(pkg) { // Upper case symbol cannot be a package name.
return "", false
}
if filepath.IsAbs(pkg) {