diff options
author | Robert Griesemer <gri@golang.org> | 2009-09-01 11:56:42 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-09-01 11:56:42 -0700 |
commit | d1fcffbf593b99333555b3463866c6d1db5028f4 (patch) | |
tree | 5b33ce6f389afa4f5d2d9db692d54c30dd1cc5d6 /src/pkg/go/doc/doc.go | |
parent | b567c251dbeda46f2a7239388934609bf1844c50 (diff) | |
download | golang-d1fcffbf593b99333555b3463866c6d1db5028f4.tar.gz |
don't show exported methods of non-exported types
R=rsc
DELTA=44 (10 added, 30 deleted, 4 changed)
OCL=34195
CL=34200
Diffstat (limited to 'src/pkg/go/doc/doc.go')
-rw-r--r-- | src/pkg/go/doc/doc.go | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go index 775c4342a..7f44eac60 100644 --- a/src/pkg/go/doc/doc.go +++ b/src/pkg/go/doc/doc.go @@ -66,36 +66,10 @@ func (doc *docReader) addType(decl *ast.GenDecl) { } -var predeclaredTypes = map[string]int { - // basic types - "bool": 0, - "byte": 0, - "int8": 0, - "int16": 0, - "int32": 0, - "int64": 0, - "uint8": 0, - "uint16": 0, - "uint32": 0, - "uint64": 0, - "float32": 0, - "float64": 0, - "string": 0, - // convenience types - "int": 0, - "uint": 0, - "uintptr": 0, - "float": 0, -} - - func (doc *docReader) lookupTypeDoc(name string) *typeDoc { if name == "" { return nil; // no type docs for anonymous types } - if _, found := predeclaredTypes[name]; found { - return nil; // no type docs for predeclared types - } if tdoc, found := doc.types[name]; found { return tdoc; } @@ -109,7 +83,11 @@ func (doc *docReader) lookupTypeDoc(name string) *typeDoc { func baseTypeName(typ ast.Expr) string { switch t := typ.(type) { case *ast.Ident: - return string(t.Value); + // if the type is not exported, the effect to + // a client is as if there were no type name + if t.IsExported() { + return string(t.Value); + } case *ast.StarExpr: return baseTypeName(t.X); } @@ -176,13 +154,16 @@ func (doc *docReader) addFunc(fun *ast.FuncDecl) { if fun.Recv != nil { // method typ := doc.lookupTypeDoc(baseTypeName(fun.Recv.Type)); - // typ should always be != nil since receiver base - // types must be named and cannot be predeclared - - // be conservative and check if typ != nil { + // exported receiver type typ.methods[name] = fun; - return; } + // otherwise don't show the method + // TODO(gri): There may be exported methods of non-exported types + // that can be called because of exported values (consts, vars, or + // function results) of that type. Could determine if that is the + // case and then show those methods in an appropriate section. + return; } // perhaps a factory function @@ -193,7 +174,7 @@ func (doc *docReader) addFunc(fun *ast.FuncDecl) { // exactly one (named or anonymous) result type typ := doc.lookupTypeDoc(baseTypeName(res.Type)); if typ != nil { - // named result type that is not predeclared + // named and exported result type typ.factories[name] = fun; return; } @@ -201,7 +182,6 @@ func (doc *docReader) addFunc(fun *ast.FuncDecl) { } // ordinary function - // (or method that was not associated to a type for some reason) doc.funcs[name] = fun; } |