aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <pcc@google.com>2014-12-28 11:32:27 -0800
committerAlan Donovan <adonovan@google.com>2015-01-13 15:48:33 +0000
commitd3e7567302afecbc7bd1297b8746ae69843b350e (patch)
treefef18b1d30aec51e4047645533230141e59d7e70
parent4f8578d2c095328e9192e9d0b0ea335c6ea3e9a5 (diff)
downloadtools-d3e7567302afecbc7bd1297b8746ae69843b350e.tar.gz
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>
-rw-r--r--go/loader/loader.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/go/loader/loader.go b/go/loader/loader.go
index ad7e14d..256cb04 100644
--- a/go/loader/loader.go
+++ b/go/loader/loader.go
@@ -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{