Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
c109705c
Commit
c109705c
authored
Jan 18, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/doc: collect imports
R=r CC=golang-dev
https://golang.org/cl/5556051
parent
f47807a5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
4 deletions
+44
-4
src/pkg/go/doc/doc.go
src/pkg/go/doc/doc.go
+1
-1
src/pkg/go/doc/exports.go
src/pkg/go/doc/exports.go
+3
-0
src/pkg/go/doc/reader.go
src/pkg/go/doc/reader.go
+22
-0
src/pkg/go/doc/testdata/b.out
src/pkg/go/doc/testdata/b.out
+3
-0
src/pkg/go/doc/testdata/template.txt
src/pkg/go/doc/testdata/template.txt
+3
-3
src/pkg/go/doc/testdata/testing.out
src/pkg/go/doc/testdata/testing.out
+12
-0
No files found.
src/pkg/go/doc/doc.go
View file @
c109705c
...
...
@@ -15,7 +15,7 @@ type Package struct {
Doc
string
Name
string
ImportPath
string
Imports
[]
string
// TODO(gri) this field is not computed at the moment
Imports
[]
string
Filenames
[]
string
Consts
[]
*
Value
Types
[]
*
Type
...
...
src/pkg/go/doc/exports.go
View file @
c109705c
...
...
@@ -124,6 +124,9 @@ func (doc *docReader) filterType(tinfo *typeInfo, typ ast.Expr) bool {
func
(
doc
*
docReader
)
filterSpec
(
spec
ast
.
Spec
)
bool
{
switch
s
:=
spec
.
(
type
)
{
case
*
ast
.
ImportSpec
:
// always keep imports so we can collect them
return
true
case
*
ast
.
ValueSpec
:
s
.
Names
=
filterIdentList
(
s
.
Names
)
if
len
(
s
.
Names
)
>
0
{
...
...
src/pkg/go/doc/reader.go
View file @
c109705c
...
...
@@ -9,6 +9,7 @@ import (
"go/token"
"regexp"
"sort"
"strconv"
)
// ----------------------------------------------------------------------------
...
...
@@ -55,6 +56,7 @@ type docReader struct {
doc
*
ast
.
CommentGroup
// package documentation, if any
pkgName
string
mode
Mode
imports
map
[
string
]
int
values
[]
*
ast
.
GenDecl
// consts and vars
types
map
[
string
]
*
typeInfo
embedded
map
[
string
]
*
typeInfo
// embedded types, possibly not exported
...
...
@@ -65,6 +67,7 @@ type docReader struct {
func
(
doc
*
docReader
)
init
(
pkgName
string
,
mode
Mode
)
{
doc
.
pkgName
=
pkgName
doc
.
mode
=
mode
doc
.
imports
=
make
(
map
[
string
]
int
)
doc
.
types
=
make
(
map
[
string
]
*
typeInfo
)
doc
.
embedded
=
make
(
map
[
string
]
*
typeInfo
)
doc
.
funcs
=
make
(
map
[
string
]
*
ast
.
FuncDecl
)
...
...
@@ -244,6 +247,13 @@ func (doc *docReader) addDecl(decl ast.Decl) {
case
*
ast
.
GenDecl
:
if
len
(
d
.
Specs
)
>
0
{
switch
d
.
Tok
{
case
token
.
IMPORT
:
// imports are handled individually
for
_
,
spec
:=
range
d
.
Specs
{
if
import_
,
err
:=
strconv
.
Unquote
(
spec
.
(
*
ast
.
ImportSpec
)
.
Path
.
Value
);
err
==
nil
{
doc
.
imports
[
import_
]
=
1
}
}
case
token
.
CONST
,
token
.
VAR
:
// constants and variables are always handled as a group
doc
.
addValue
(
d
)
...
...
@@ -346,6 +356,17 @@ func (doc *docReader) addFile(src *ast.File) {
// ----------------------------------------------------------------------------
// Conversion to external representation
func
(
doc
*
docReader
)
makeImports
()
[]
string
{
list
:=
make
([]
string
,
len
(
doc
.
imports
))
i
:=
0
for
import_
:=
range
doc
.
imports
{
list
[
i
]
=
import_
i
++
}
sort
.
Strings
(
list
)
return
list
}
type
sortValue
[]
*
Value
func
(
p
sortValue
)
Len
()
int
{
return
len
(
p
)
}
...
...
@@ -661,6 +682,7 @@ func (doc *docReader) newDoc(importpath string, filenames []string) *Package {
// doc.funcs and thus must be called before any other
// function consuming those lists
p
.
Types
=
doc
.
makeTypes
(
doc
.
types
)
p
.
Imports
=
doc
.
makeImports
()
p
.
Consts
=
makeValues
(
doc
.
values
,
token
.
CONST
)
p
.
Vars
=
makeValues
(
doc
.
values
,
token
.
VAR
)
p
.
Funcs
=
makeFuncs
(
doc
.
funcs
)
...
...
src/pkg/go/doc/testdata/b.out
View file @
c109705c
...
...
@@ -4,6 +4,9 @@ PACKAGE b
IMPORTPATH
testdata/b
IMPORTS
a
FILENAMES
testdata/b.go
...
...
src/pkg/go/doc/testdata/template.txt
View file @
c109705c
...
...
@@ -4,10 +4,10 @@ PACKAGE {{.Name}}
IMPORTPATH
{{.ImportPath}}
{{with .Imports}}
IMPORTS
{{with .Imports}}IMPORTS
{{range .}} {{.}}
{{end}}{{end}}{{/*
{{end}}
{{end}}{{/*
*/}}FILENAMES
{{range .Filenames}} {{.}}
...
...
src/pkg/go/doc/testdata/testing.out
View file @
c109705c
...
...
@@ -4,6 +4,18 @@ PACKAGE testing
IMPORTPATH
testdata/testing
IMPORTS
bytes
flag
fmt
io
os
runtime
runtime/pprof
strconv
strings
time
FILENAMES
testdata/benchmark.go
testdata/example.go
...
...
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