mirror of
https://github.com/golang/go
synced 2024-11-18 20:24:41 -07: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:
parent
4f8578d2c0
commit
d3e7567302
@ -226,6 +226,19 @@ type Config struct {
|
|||||||
// values indicate whether to augment the package by *_test.go
|
// values indicate whether to augment the package by *_test.go
|
||||||
// files in a second pass.
|
// files in a second pass.
|
||||||
ImportPkgs map[string]bool
|
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 {
|
type CreatePkg struct {
|
||||||
@ -828,6 +841,9 @@ func typeCheckFiles(info *PackageInfo, files ...*ast.File) {
|
|||||||
|
|
||||||
func (imp *importer) newPackageInfo(path string) *PackageInfo {
|
func (imp *importer) newPackageInfo(path string) *PackageInfo {
|
||||||
pkg := types.NewPackage(path, "")
|
pkg := types.NewPackage(path, "")
|
||||||
|
if imp.conf.PackageCreated != nil {
|
||||||
|
imp.conf.PackageCreated(pkg)
|
||||||
|
}
|
||||||
info := &PackageInfo{
|
info := &PackageInfo{
|
||||||
Pkg: pkg,
|
Pkg: pkg,
|
||||||
Info: types.Info{
|
Info: types.Info{
|
||||||
|
Loading…
Reference in New Issue
Block a user