1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package doc extracts source code documentation from a Go AST.
13 // Package is the documentation for an entire package.
20 Notes
map[string][]*Note
21 // DEPRECATED. For backward compatibility Bugs is still populated,
22 // but all new code should use Notes instead.
32 // Value is the documentation for a (possibly grouped) var or const declaration.
35 Names
[]string // var or const names in declaration order
41 // Type is the documentation for a type declaration.
47 // associated declarations
48 Consts
[]*Value
// sorted list of constants of (mostly) this type
49 Vars
[]*Value
// sorted list of variables of (mostly) this type
50 Funcs
[]*Func
// sorted list of functions returning this type
51 Methods
[]*Func
// sorted list of methods (including embedded ones) of this type
54 // Func is the documentation for a func declaration.
61 // (for functions, these fields have the respective zero value)
62 Recv
string // actual receiver "T" or "*T"
63 Orig
string // original receiver "T" or "*T"
64 Level
int // embedding level; 0 means not embedded
67 // A Note represents a marked comment starting with "MARKER(uid): note body".
68 // Any note with a marker of 2 or more upper case [A-Z] letters and a uid of
69 // at least one character is recognized. The ":" following the uid is optional.
70 // Notes are collected in the Package.Notes map indexed by the notes marker.
72 Pos
, End token
.Pos
// position range of the comment containing the marker
73 UID
string // uid found with the marker
74 Body
string // note body text
77 // Mode values control the operation of New.
81 // extract documentation for all package-level declarations,
82 // not just exported ones
83 AllDecls Mode
= 1 << iota
85 // show all embedded methods, not just the ones of
86 // invisible (unexported) anonymous fields
90 // New computes the package documentation for the given package AST.
91 // New takes ownership of the AST pkg and may edit or overwrite it.
93 func New(pkg
*ast
.Package
, importPath
string, mode Mode
) *Package
{
95 r
.readPackage(pkg
, mode
)
101 ImportPath
: importPath
,
102 Imports
: sortedKeys(r
.imports
),
103 Filenames
: r
.filenames
,
105 Bugs
: noteBodies(r
.notes
["BUG"]),
106 Consts
: sortedValues(r
.values
, token
.CONST
),
107 Types
: sortedTypes(r
.types
, mode
&AllMethods
!= 0),
108 Vars
: sortedValues(r
.values
, token
.VAR
),
109 Funcs
: sortedFuncs(r
.funcs
, true),