FileExports trims the AST for a Go source file in place such that only exported nodes remain: all top-level identifiers which are not exported and their associated information (such as type, initial value, or function body) are removed. Non-exported fields and methods of exported types are stripped. The File.Comments list is not changed. FileExports reports whether there are exported declarations.
PackageExports trims the AST for a Go package in place such that only exported nodes remain. The pkg.Files list is not changed, so that file names and top-level package comments don't get lost. PackageExports reports whether there are exported declarations; it returns false otherwise.
fieldName assumes that x is the type of an anonymous field and returns the corresponding field name. If x is not an acceptable anonymous field, the result is nil.
FilterDecl trims the AST for a Go declaration in place by removing all names (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. FilterDecl reports whether there are any declared names left after filtering.
FilterFile trims the AST for a Go file in place by removing all names from top-level declarations (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. If the declaration is empty afterwards, the declaration is removed from the AST. Import declarations are always removed. The File.Comments list is not changed. FilterFile reports whether there are any top-level declarations left after filtering.
FilterPackage trims the AST for a Go package in place by removing all names from top-level declarations (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. If the declaration is empty afterwards, the declaration is removed from the AST. The pkg.Files list is not changed, so that file names and top-level package comments don't get lost. FilterPackage reports whether there are any top-level declarations left after filtering.
nameOf returns the function (foo) or method name (foo.bar) for the given function declaration. If the AST is incorrect for the receiver, it assumes a function instead.
MergePackageFiles creates a file AST by merging the ASTs of the files belonging to a package. The mode flags control merging behavior.
Count the number of package docs, comments and declarations across all package files. Also, compute sorted list of filenames, so that subsequent iterations can always iterate in the same order.
Collect package comments from all package files into a single CommentGroup - the collected package documentation. In general there should be only one file with a package comment; but it's better to collect extra comments than drop them on the floor.
var []Declif > 0 {
= make([]Decl, )
:= make(map[string]int) // map of func name -> decls index
:= 0// current index
:= 0// number of filtered entriesfor , := range {
:= .Files[]
for , := range .Decls {
A language entity may be declared multiple times in different package files; only at build time declarations must be unique. For now, exclude multiple declarations of functions - keep the one with documentation. TODO(gri): Expand this filtering to other entities (const, type, vars) if multiple declarations are common.
Eliminate nil entries from the decls list if entries were filtered. We do this using a 2nd pass in order to not disturb the original declaration order in the source (otherwise, this would also invalidate the monotonically increasing position info within a single file).
if > 0 {
= 0for , := range {
if != nil {
[] =
++
}
}
= [0:]
}
}
TODO: consider handling cases where: - 2 imports exist with the same import path but have different local names (one should probably keep both of them) - 2 imports exist but only one has a comment - 2 imports exist and they both have (possibly different) comments
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.