mirror of
https://github.com/golang/go
synced 2024-11-19 00:34:40 -07:00
go/loader: rename Example functions to appease godoc
And other minor cosmetic tweaks. Change-Id: Ic75d405e6eca8f29b7e97de66fb86f1f39bcae1e Reviewed-on: https://go-review.googlesource.com/9035 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
9c57c19a58
commit
41d9a0e7b2
@ -15,7 +15,7 @@ import (
|
|||||||
"golang.org/x/tools/go/loader"
|
"golang.org/x/tools/go/loader"
|
||||||
)
|
)
|
||||||
|
|
||||||
func printProg(prog *loader.Program) {
|
func printProgram(prog *loader.Program) {
|
||||||
// Created packages are the initial packages specified by a call
|
// Created packages are the initial packages specified by a call
|
||||||
// to CreateFromFilenames or CreateFromFiles.
|
// to CreateFromFilenames or CreateFromFiles.
|
||||||
var names []string
|
var names []string
|
||||||
@ -58,11 +58,11 @@ func printFilenames(fset *token.FileSet, info *loader.PackageInfo) {
|
|||||||
fmt.Printf("%s.Files: %s\n", info.Pkg.Path(), names)
|
fmt.Printf("%s.Files: %s\n", info.Pkg.Path(), names)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExampleFromArgs loads a set of packages and all their dependencies
|
// This example loads a set of packages and all of their dependencies
|
||||||
// from a typical command-line. FromArgs parses a command line and
|
// from a typical command-line. FromArgs parses a command line and
|
||||||
// makes calls to the other methods of Config shown in the examples that
|
// makes calls to the other methods of Config shown in the examples that
|
||||||
// follow.
|
// follow.
|
||||||
func ExampleFromArgs() {
|
func ExampleConfig_FromArgs() {
|
||||||
args := []string{"mytool", "unicode/utf8", "errors", "runtime", "--", "foo", "bar"}
|
args := []string{"mytool", "unicode/utf8", "errors", "runtime", "--", "foo", "bar"}
|
||||||
const wantTests = false
|
const wantTests = false
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func ExampleFromArgs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("rest: %s\n", rest)
|
fmt.Printf("rest: %s\n", rest)
|
||||||
printProg(prog)
|
printProgram(prog)
|
||||||
// Output:
|
// Output:
|
||||||
// rest: [foo bar]
|
// rest: [foo bar]
|
||||||
// created: []
|
// created: []
|
||||||
@ -83,9 +83,9 @@ func ExampleFromArgs() {
|
|||||||
// all: [errors runtime unicode/utf8]
|
// all: [errors runtime unicode/utf8]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExampleCreateFromFilenames loads a single package (without tests) and
|
// This example creates and type-checks a single package (without tests)
|
||||||
// all its dependencies from a list of filenames.
|
// from a list of filenames, and loads all of its dependencies.
|
||||||
func ExampleCreateFromFilenames() {
|
func ExampleConfig_CreateFromFilenames() {
|
||||||
var conf loader.Config
|
var conf loader.Config
|
||||||
filename := filepath.Join(runtime.GOROOT(), "src/container/heap/heap.go")
|
filename := filepath.Join(runtime.GOROOT(), "src/container/heap/heap.go")
|
||||||
conf.CreateFromFilenames("container/heap", filename)
|
conf.CreateFromFilenames("container/heap", filename)
|
||||||
@ -94,7 +94,7 @@ func ExampleCreateFromFilenames() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
printProg(prog)
|
printProgram(prog)
|
||||||
// Output:
|
// Output:
|
||||||
// created: [container/heap]
|
// created: [container/heap]
|
||||||
// imported: []
|
// imported: []
|
||||||
@ -116,9 +116,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
// ExampleCreateFromFiles loads a package and all its dependencies from
|
// This example creates and type-checks a package from a list of
|
||||||
// a list of already-parsed files.
|
// already-parsed files, and loads all its dependencies.
|
||||||
func ExampleCreateFromFiles() {
|
func ExampleConfig_CreateFromFiles() {
|
||||||
var conf loader.Config
|
var conf loader.Config
|
||||||
f, err := conf.ParseFile("hello.go", hello)
|
f, err := conf.ParseFile("hello.go", hello)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -130,7 +130,7 @@ func ExampleCreateFromFiles() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
printProg(prog)
|
printProgram(prog)
|
||||||
printFilenames(prog.Fset, prog.Package("strconv"))
|
printFilenames(prog.Fset, prog.Package("strconv"))
|
||||||
// Output:
|
// Output:
|
||||||
// created: [hello]
|
// created: [hello]
|
||||||
@ -140,12 +140,13 @@ func ExampleCreateFromFiles() {
|
|||||||
// strconv.Files: [atob.go atof.go atoi.go decimal.go extfloat.go ftoa.go isprint.go itoa.go quote.go]
|
// strconv.Files: [atob.go atof.go atoi.go decimal.go extfloat.go ftoa.go isprint.go itoa.go quote.go]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExampleImport loads three packages and all their dependencies.
|
// This example imports three packages, including the tests for one of
|
||||||
func ExampleImport() {
|
// them, and loads all their dependencies.
|
||||||
|
func ExampleConfig_Import() {
|
||||||
// ImportWithTest("strconv") causes strconv to include
|
// ImportWithTest("strconv") causes strconv to include
|
||||||
// internal_test.go, and creates an external test package,
|
// internal_test.go, and creates an external test package,
|
||||||
// strconv_test.
|
// strconv_test.
|
||||||
// (Compare with output of ExampleCreateFromFiles.)
|
// (Compare with the example of CreateFromFiles.)
|
||||||
|
|
||||||
var conf loader.Config
|
var conf loader.Config
|
||||||
conf.Import("unicode/utf8")
|
conf.Import("unicode/utf8")
|
||||||
@ -156,7 +157,7 @@ func ExampleImport() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
printProg(prog)
|
printProgram(prog)
|
||||||
printFilenames(prog.Fset, prog.Package("strconv"))
|
printFilenames(prog.Fset, prog.Package("strconv"))
|
||||||
printFilenames(prog.Fset, prog.Package("strconv_test"))
|
printFilenames(prog.Fset, prog.Package("strconv_test"))
|
||||||
// Output:
|
// Output:
|
||||||
|
Loading…
Reference in New Issue
Block a user