Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
a4129988
Commit
a4129988
authored
May 26, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godoc: collect package comments from all package files, not just the first one found
R=r CC=golang-dev
https://golang.org/cl/1331041
parent
f199f292
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
doc.go
src/pkg/go/doc/doc.go
+23
-6
No files found.
src/pkg/go/doc/doc.go
View file @
a4129988
...
@@ -53,6 +53,28 @@ func (doc *docReader) init(pkgName string) {
...
@@ -53,6 +53,28 @@ func (doc *docReader) init(pkgName string) {
}
}
func
(
doc
*
docReader
)
addDoc
(
comments
*
ast
.
CommentGroup
)
{
if
doc
.
doc
==
nil
{
// common case: just one package comment
doc
.
doc
=
comments
return
}
// More than one package comment: Usually there will be only
// one file with a package comment, but it's better to collect
// all comments than drop them on the floor.
// (This code isn't particularly clever - no amortized doubling is
// used - but this situation occurs rarely and is not time-critical.)
n1
:=
len
(
doc
.
doc
.
List
)
n2
:=
len
(
comments
.
List
)
list
:=
make
([]
*
ast
.
Comment
,
n1
+
1
+
n2
)
// + 1 for separator line
copy
(
list
,
doc
.
doc
.
List
)
list
[
n1
]
=
&
ast
.
Comment
{
token
.
Position
{},
[]
byte
(
"//"
)}
// separator line
copy
(
list
[
n1
+
1
:
],
comments
.
List
)
doc
.
doc
=
&
ast
.
CommentGroup
{
list
}
}
func
(
doc
*
docReader
)
addType
(
decl
*
ast
.
GenDecl
)
{
func
(
doc
*
docReader
)
addType
(
decl
*
ast
.
GenDecl
)
{
spec
:=
decl
.
Specs
[
0
]
.
(
*
ast
.
TypeSpec
)
spec
:=
decl
.
Specs
[
0
]
.
(
*
ast
.
TypeSpec
)
typ
:=
doc
.
lookupTypeDoc
(
spec
.
Name
.
Name
())
typ
:=
doc
.
lookupTypeDoc
(
spec
.
Name
.
Name
())
...
@@ -275,12 +297,7 @@ var (
...
@@ -275,12 +297,7 @@ var (
func
(
doc
*
docReader
)
addFile
(
src
*
ast
.
File
)
{
func
(
doc
*
docReader
)
addFile
(
src
*
ast
.
File
)
{
// add package documentation
// add package documentation
if
src
.
Doc
!=
nil
{
if
src
.
Doc
!=
nil
{
// TODO(gri) This won't do the right thing if there is more
doc
.
addDoc
(
src
.
Doc
)
// than one file with package comments. Consider
// using ast.MergePackageFiles which handles these
// comments correctly (but currently looses BUG(...)
// comments).
doc
.
doc
=
src
.
Doc
src
.
Doc
=
nil
// doc consumed - remove from ast.File node
src
.
Doc
=
nil
// doc consumed - remove from ast.File node
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment