mirror of
https://github.com/golang/go
synced 2024-11-13 12:30:21 -07:00
go/types: rename Importer2 to ImporterFrom
Per https://groups.google.com/forum/#!topic/golang-dev/javNmryAh0I Change-Id: I08d7cbc94da4fc61c848f3dbee4637bf8fcfeb01 Reviewed-on: https://go-review.googlesource.com/18630 Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
8c9ef9dd0a
commit
66330d8c6c
@ -186,6 +186,10 @@ pkg go/constant, func ToFloat(Value) Value
|
|||||||
pkg go/constant, func ToInt(Value) Value
|
pkg go/constant, func ToInt(Value) Value
|
||||||
pkg go/constant, type Value interface, ExactString() string
|
pkg go/constant, type Value interface, ExactString() string
|
||||||
pkg go/types, method (*Package) SetName(string)
|
pkg go/types, method (*Package) SetName(string)
|
||||||
|
pkg go/types, type ImportMode int
|
||||||
|
pkg go/types, type ImporterFrom interface { Import, ImportFrom }
|
||||||
|
pkg go/types, type ImporterFrom interface, Import(string) (*Package, error)
|
||||||
|
pkg go/types, type ImporterFrom interface, ImportFrom(string, string, ImportMode) (*Package, error)
|
||||||
pkg html/template, func IsTrue(interface{}) (bool, bool)
|
pkg html/template, func IsTrue(interface{}) (bool, bool)
|
||||||
pkg html/template, method (*Template) DefinedTemplates() string
|
pkg html/template, method (*Template) DefinedTemplates() string
|
||||||
pkg image, func NewNYCbCrA(Rectangle, YCbCrSubsampleRatio) *NYCbCrA
|
pkg image, func NewNYCbCrA(Rectangle, YCbCrSubsampleRatio) *NYCbCrA
|
||||||
|
@ -50,7 +50,7 @@ func For(compiler string, lookup Lookup) types.Importer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default returns an Importer for the compiler that built the running binary.
|
// Default returns an Importer for the compiler that built the running binary.
|
||||||
// If available, the result implements types.Importer2.
|
// If available, the result implements types.ImporterFrom.
|
||||||
func Default() types.Importer {
|
func Default() types.Importer {
|
||||||
return For(runtime.Compiler, nil)
|
return For(runtime.Compiler, nil)
|
||||||
}
|
}
|
||||||
@ -60,10 +60,10 @@ func Default() types.Importer {
|
|||||||
type gcimports map[string]*types.Package
|
type gcimports map[string]*types.Package
|
||||||
|
|
||||||
func (m gcimports) Import(path string) (*types.Package, error) {
|
func (m gcimports) Import(path string) (*types.Package, error) {
|
||||||
return m.Import2(path, "" /* no vendoring */, 0)
|
return m.ImportFrom(path, "" /* no vendoring */, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m gcimports) Import2(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
|
func (m gcimports) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
|
||||||
if mode != 0 {
|
if mode != 0 {
|
||||||
panic("mode must be 0")
|
panic("mode must be 0")
|
||||||
}
|
}
|
||||||
@ -78,10 +78,10 @@ type gccgoimports struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *gccgoimports) Import(path string) (*types.Package, error) {
|
func (m *gccgoimports) Import(path string) (*types.Package, error) {
|
||||||
return m.Import2(path, "" /* no vendoring */, 0)
|
return m.ImportFrom(path, "" /* no vendoring */, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *gccgoimports) Import2(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
|
func (m *gccgoimports) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
|
||||||
if mode != 0 {
|
if mode != 0 {
|
||||||
panic("mode must be 0")
|
panic("mode must be 0")
|
||||||
}
|
}
|
||||||
|
@ -54,37 +54,37 @@ func (err Error) Error() string {
|
|||||||
// An Importer resolves import paths to Packages.
|
// An Importer resolves import paths to Packages.
|
||||||
//
|
//
|
||||||
// CAUTION: This interface does not support the import of locally
|
// CAUTION: This interface does not support the import of locally
|
||||||
// vendored packages. See also https://golang.org/s/go15vendor.
|
// vendored packages. See https://golang.org/s/go15vendor.
|
||||||
// If possible, external implementations should implement Importer2.
|
// If possible, external implementations should implement ImporterFrom.
|
||||||
type Importer interface {
|
type Importer interface {
|
||||||
// Import returns the imported package for the given import
|
// Import returns the imported package for the given import
|
||||||
// path, or an error if the package couldn't be imported.
|
// path, or an error if the package couldn't be imported.
|
||||||
// Two calls to Import with the same path and srcDir return
|
// Two calls to Import with the same path return the same
|
||||||
// the same package.
|
// package.
|
||||||
Import(path string) (*Package, error)
|
Import(path string) (*Package, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportMode is reserved for future use.
|
// ImportMode is reserved for future use.
|
||||||
type ImportMode int
|
type ImportMode int
|
||||||
|
|
||||||
// An Importer2 resolves import paths to packages; it
|
// An ImporterFrom resolves import paths to packages; it
|
||||||
// supports vendoring per https://golang.org/s/go15vendor.
|
// supports vendoring per https://golang.org/s/go15vendor.
|
||||||
// Use go/importer to obtain an Importer2 implementation.
|
// Use go/importer to obtain an ImporterFrom implementation.
|
||||||
type Importer2 interface {
|
type ImporterFrom interface {
|
||||||
// Importer is present for backward-compatibility. Calling
|
// Importer is present for backward-compatibility. Calling
|
||||||
// Import(path) is the same as calling Import(path, "", 0);
|
// Import(path) is the same as calling ImportFrom(path, "", 0);
|
||||||
// i.e., locally vendored packages may not be found.
|
// i.e., locally vendored packages may not be found.
|
||||||
// The types package does not call Import if an Importer2
|
// The types package does not call Import if an ImporterFrom
|
||||||
// is present.
|
// is present.
|
||||||
Importer
|
Importer
|
||||||
|
|
||||||
// Import2 returns the imported package for the given import
|
// ImportFrom returns the imported package for the given import
|
||||||
// path when imported by the package in srcDir, or an error
|
// path when imported by the package in srcDir, or an error
|
||||||
// if the package couldn't be imported. The mode value must
|
// if the package couldn't be imported. The mode value must
|
||||||
// be 0; it is reserved for future use.
|
// be 0; it is reserved for future use.
|
||||||
// Two calls to Import2 with the same path and srcDir return
|
// Two calls to ImportFrom with the same path and srcDir return
|
||||||
// the same package.
|
// the same package.
|
||||||
Import2(path, srcDir string, mode ImportMode) (*Package, error)
|
ImportFrom(path, srcDir string, mode ImportMode) (*Package, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Config specifies the configuration for type checking.
|
// A Config specifies the configuration for type checking.
|
||||||
@ -114,8 +114,8 @@ type Config struct {
|
|||||||
|
|
||||||
// An importer is used to import packages referred to from
|
// An importer is used to import packages referred to from
|
||||||
// import declarations.
|
// import declarations.
|
||||||
// If the installed importer implements Importer2, the type
|
// If the installed importer implements ImporterFrom, the type
|
||||||
// checker calls Import2 instead of Import.
|
// checker calls ImportFrom instead of Import.
|
||||||
// The type checker reports an error if an importer is needed
|
// The type checker reports an error if an importer is needed
|
||||||
// but none was installed.
|
// but none was installed.
|
||||||
Importer Importer
|
Importer Importer
|
||||||
|
@ -187,10 +187,10 @@ func (check *Checker) collectObjects() {
|
|||||||
// ordinary import
|
// ordinary import
|
||||||
if importer := check.conf.Importer; importer == nil {
|
if importer := check.conf.Importer; importer == nil {
|
||||||
err = fmt.Errorf("Config.Importer not installed")
|
err = fmt.Errorf("Config.Importer not installed")
|
||||||
} else if importer2, ok := importer.(Importer2); ok {
|
} else if importerFrom, ok := importer.(ImporterFrom); ok {
|
||||||
imp, err = importer2.Import2(path, srcDir, 0)
|
imp, err = importerFrom.ImportFrom(path, srcDir, 0)
|
||||||
if imp == nil && err == nil {
|
if imp == nil && err == nil {
|
||||||
err = fmt.Errorf("Config.Importer.Import2(%s, %s, 0) returned nil but no error", path, pkg.path)
|
err = fmt.Errorf("Config.Importer.ImportFrom(%s, %s, 0) returned nil but no error", path, pkg.path)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
imp, err = importer.Import(path)
|
imp, err = importer.Import(path)
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type resolveTestImporter struct {
|
type resolveTestImporter struct {
|
||||||
importer Importer2
|
importer ImporterFrom
|
||||||
imported map[string]bool
|
imported map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,15 +26,15 @@ func (imp *resolveTestImporter) Import(string) (*Package, error) {
|
|||||||
panic("should not be called")
|
panic("should not be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (imp *resolveTestImporter) Import2(path, srcDir string, mode ImportMode) (*Package, error) {
|
func (imp *resolveTestImporter) ImportFrom(path, srcDir string, mode ImportMode) (*Package, error) {
|
||||||
if mode != 0 {
|
if mode != 0 {
|
||||||
panic("mode must be 0")
|
panic("mode must be 0")
|
||||||
}
|
}
|
||||||
if imp.importer == nil {
|
if imp.importer == nil {
|
||||||
imp.importer = importer.Default().(Importer2)
|
imp.importer = importer.Default().(ImporterFrom)
|
||||||
imp.imported = make(map[string]bool)
|
imp.imported = make(map[string]bool)
|
||||||
}
|
}
|
||||||
pkg, err := imp.importer.Import2(path, srcDir, mode)
|
pkg, err := imp.importer.ImportFrom(path, srcDir, mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user