imports: allow dirPackageInfo to be overridden
Change-Id: Ie90d2681e364e2a3f905675db266cb8960e08277 Reviewed-on: https://go-review.googlesource.com/39995 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
fc77adfcad
commit
663269851c
|
|
@ -73,8 +73,11 @@ type packageInfo struct {
|
||||||
Globals map[string]bool // symbol => true
|
Globals map[string]bool // symbol => true
|
||||||
}
|
}
|
||||||
|
|
||||||
// dirPackageInfo gets information from other files in the package.
|
// dirPackageInfo exposes the dirPackageInfoFile function so that it can be overridden.
|
||||||
func dirPackageInfo(srcDir, filename string) (*packageInfo, error) {
|
var dirPackageInfo = dirPackageInfoFile
|
||||||
|
|
||||||
|
// dirPackageInfoFile gets information from other files in the package.
|
||||||
|
func dirPackageInfoFile(pkgName, srcDir, filename string) (*packageInfo, error) {
|
||||||
considerTests := strings.HasSuffix(filename, "_test.go")
|
considerTests := strings.HasSuffix(filename, "_test.go")
|
||||||
|
|
||||||
// Handle file from stdin
|
// Handle file from stdin
|
||||||
|
|
@ -178,7 +181,7 @@ func fixImports(fset *token.FileSet, f *ast.File, filename string) (added []stri
|
||||||
}
|
}
|
||||||
if !loadedPackageInfo {
|
if !loadedPackageInfo {
|
||||||
loadedPackageInfo = true
|
loadedPackageInfo = true
|
||||||
packageInfo, _ = dirPackageInfo(srcDir, filename)
|
packageInfo, _ = dirPackageInfo(f.Name.Name, srcDir, filename)
|
||||||
}
|
}
|
||||||
if decls[pkgName] == nil && (packageInfo == nil || !packageInfo.Globals[pkgName]) {
|
if decls[pkgName] == nil && (packageInfo == nil || !packageInfo.Globals[pkgName]) {
|
||||||
refs[pkgName][v.Sel.Name] = true
|
refs[pkgName][v.Sel.Name] = true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue