1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:48:32 -06:00

go/loader: introduce PackageCreated hook

PackageCreated is a hook called when a types.Package
is created but before it has been populated.

The package's import Path() and Scope() are defined,
but not its Name() since no package declaration has
been seen yet.

Clients may use this to insert synthetic items into
the package scope, for example.

Change-Id: I210a0c4c766f03f715f03f26d5cd765f15f56e04
Reviewed-on: https://go-review.googlesource.com/2138
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Peter Collingbourne 2014-12-28 11:32:27 -08:00 committed by Alan Donovan
parent 4f8578d2c0
commit d3e7567302

View File

@ -226,6 +226,19 @@ type Config struct {
// values indicate whether to augment the package by *_test.go
// files in a second pass.
ImportPkgs map[string]bool
// PackageCreated is a hook called when a types.Package
// is created but before it has been populated.
//
// The package's import Path() and Scope() are defined,
// but not its Name() since no package declaration has
// been seen yet.
//
// Clients may use this to insert synthetic items into
// the package scope, for example.
//
// It must be safe to call concurrently from multiple goroutines.
PackageCreated func(*types.Package)
}
type CreatePkg struct {
@ -828,6 +841,9 @@ func typeCheckFiles(info *PackageInfo, files ...*ast.File) {
func (imp *importer) newPackageInfo(path string) *PackageInfo {
pkg := types.NewPackage(path, "")
if imp.conf.PackageCreated != nil {
imp.conf.PackageCreated(pkg)
}
info := &PackageInfo{
Pkg: pkg,
Info: types.Info{