srcimporter

package
v1.14.3-beta.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2019 License: Apache-2.0, BSD-3-Clause Imports: 10 Imported by: 0

README

Files copied from https://github.com/golang/go/blob/5f0a9ba1342674b3209c13035b5aa39a96dbd80c/src/go/internal/srcimporter/srcimporter.go at commit 5f0a9ba1342674b3209c13035b5aa39a96dbd80c.

Used in k8s.io/kubernetes/test/typecheck. Need to copy here, as it's marked as a go/internal library.
Only modification is to remove the go/internal/srcimporter import alias.

Documentation

Overview

Package srcimporter implements importing directly from source files rather than installed packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Importer

type Importer struct {
	// contains filtered or unexported fields
}

An Importer provides the context for importing packages from source code.

func New

func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Package) *Importer

NewImporter returns a new Importer for the given context, file set, and map of packages. The context is used to resolve import paths to package paths, and identifying the files belonging to the package. If the context provides non-nil file system functions, they are used instead of the regular package os functions. The file set is used to track position information of package files; and imported packages are added to the packages map.

func (*Importer) Import

func (p *Importer) Import(path string) (*types.Package, error)

Import(path) is a shortcut for ImportFrom(path, ".", 0).

func (*Importer) ImportFrom

func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error)

ImportFrom imports the package with the given import path resolved from the given srcDir, adds the new package to the set of packages maintained by the importer, and returns the package. Package path resolution and file system operations are controlled by the context maintained with the importer. The import mode must be zero but is otherwise ignored. Packages that are not comprised entirely of pure Go files may fail to import because the type checker may not be able to determine all exported entities (e.g. due to cgo dependencies).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL