// Given a set of interfaces, return a map from import identifier to package to
// use that identifier for, containing elements for each import needed by the
// mock versions of those interfaces in a package with the given path.
189853
func getImports(
	interfaces []reflect.Type,
	pkgPath string) importMap {
	imports := make(importMap)
	for _, it := range interfaces {
		addImportForType(imports, it)
		addImportsForInterfaceMethods(imports, it)
	}

	// Make sure there are imports for other types used by the generated code
	// itself.
	imports["fmt"] = "fmt"
	imports["oglemock"] = "github.com/jacobsa/oglemock"
	imports["runtime"] = "runtime"
	imports["unsafe"] = "unsafe"

	// Remove any self-imports generated above.
	for k, v := range imports {
		if v == pkgPath {
			delete(imports, k)
		}
	}

	return imports
}
986505
func RegistryToInterfaceMap(r metrics.Registry) map[string]interface{} {
	metricsMap := registryToMap(r)
	interfaceMap := make(map[string]interface{})
	for k, v := range metricsMap {
		interfaceMap[k] = v
	}
	return interfaceMap
}
658711
func GenericPath(mg MinimalGraphics, x, y []int, style Style) {
	n := imin(len(x), len(y))
	for i := 1; i < n; i++ {
		mg.Line(x[i-1], y[i-1], x[i], y[i], style)
	}
}
800763
func (s *selection) getRequiredPackagesIn(id ProjectIdentifier) map[string]int {
	// TODO(sdboyer) this is horribly inefficient to do on the fly; we need a method to
	// precompute it on pushing a new dep, and preferably with an immut
	// structure so that we can pop with zero cost.
	uniq := make(map[string]int)
	for _, dep := range s.deps[id.ProjectRoot] {
		for _, pkg := range dep.dep.pl {
			uniq[pkg] = uniq[pkg] + 1
		}
	}

	return uniq
}
1036962
func (w *Wrapper) importDirsUsed() []string {
	used := []string{}
	for _, imp := range w.ImportDirs {
		for _, proto := range w.ProtoFiles {
			if strings.HasPrefix(proto, imp) {
				used = append(used, imp)
				break
			}
		}
	}
	return used
}
811524
func getPackageImportMap(astPackage *ast.Package) map[string]string {

	result := make(map[string]string)

	// Iterate files in this package
	// (There's also an *ast.Package.Imports property but it seems to be empty)
	for fileName, file := range astPackage.Files {
		// Iterate imports in this file
		for _, importSpec := range file.Imports {
			// Remove quotes
			packagePath := importSpec.Path.Value[1 : len(importSpec.Path.Value)-1]

			// Determine package name
			var packageName string
			if importSpec.Name != nil {
				// Package is aliased to another name
				packageName = importSpec.Name.Name

			} else {
				// Use the default name, the path's last element
				tmp := strings.Split(packagePath, "/")
				packageName = tmp[len(tmp)-1]
			}

			// Check for naming conflicts
			tmp, exists := result[packageName]
			if exists && tmp != packagePath {
				panic(fmt.Sprintf("Package naming conflict in %s: %s => %s, was already %s\n",
					fileName, packageName, tmp, packagePath))
			}

			result[packageName] = packagePath
		}

		// Add this file's local path to import list
		// - there may not be other references to this package
		tmp, exists := result[file.Name.Name]
		if exists && tmp != path.Dir(fileName) {
			fmt.Printf("WARNING: Possible package naming conflict in file %q: package %q "+
				"references both importdir %q and relative dir %q\n",
				fileName, file.Name.Name, tmp, path.Dir(fileName))
		}
		result[file.Name.Name] = path.Dir(fileName)
	}

	return result
}
857521
func (s *Server) Imports() []string {
	imports := map[string]struct{}{}

	for _, r := range s.Resources {
		imports[r.apiName()] = struct{}{}
	}
	return commons.MapToSortedStrings(imports)
}
210018
func (v *TypeReference) GetImportPath() (o string) {
	if v != nil {
		o = v.ImportPath
	}
	return
}
278338
func getPackage(path string, files []string, fset *token.FileSet) (*ast.Package, error) {
	var filter func(f os.FileInfo) bool
	if len(files) > 0 {
		fm := make(map[string]bool, len(files))
		for _, f := range files {
			fm[f] = true
		}

		filter = func(f os.FileInfo) bool {
			return fm[f.Name()]
		}
	}

	pkgs, err := parser.ParseDir(fset, path, filter, parser.ParseComments)
	if err != nil {
		return nil, fmt.Errorf("failed to parse directory: %v", err)
	}

	for name, pkg := range pkgs {
		if !strings.HasSuffix(name, "_test") {
			return pkg, nil
		}
	}
	return nil, fmt.Errorf("no non-test packages found in %s", path)
}
527253
func addImportsForInterfaceMethods(imports importMap, it reflect.Type) {
	// Handle each method.
	for i := 0; i < it.NumMethod(); i++ {
		m := it.Method(i)
		addImportsForType(imports, m.Type)
	}
}
596582
func (p *Imports) Get(prev, path string) ([]byte, error) {
	p.RLock()
	defer p.RUnlock()
	for _, imp := range p.m {
		if imp.Prev == prev && imp.Path == path {
			return imp.bytes, nil
		}
	}
	return nil, ErrImportNotFound
}
892022
func (imp *imports) AddImportsFrom(t types.Type) {
	switch el := t.(type) {
	case *types.Basic:
	case *types.Slice:
		imp.AddImportsFrom(el.Elem())
	case *types.Pointer:
		imp.AddImportsFrom(el.Elem())
	case *types.Named:
		pkg := el.Obj().Pkg()
		if pkg == nil {
			return
		}
		if pkg.Name() == imp.currentpkg {
			return
		}
		imp.imp[cleanImportPath(pkg.Path())] = pkg.Name()
	case *types.Tuple:
		for i := 0; i < el.Len(); i++ {
			imp.AddImportsFrom(el.At(i).Type())
		}
	default:
	}
}
224809
func getImportPathList(rootPath string) <-chan string {
	c := make(chan string)

	go func() {
		defer close(c)

		filemode, err := getFileMode(rootPath)
		if err != nil {
			warn(err)
			return
		}

		if filemode.IsDir() {
			// Directory
			filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error {
				matched, err := filepath.Match("*.json", info.Name())
				if err != nil {
					warn(err)
					return nil
				}
				if matched {
					c <- path
				}
				return nil
			})
		} else if filemode.IsRegular() {
			// Single File
			c <- rootPath
		}
	}()

	return c
}
851144
func importPaths(args []string) []string {
	args = importPathsNoDotExpansion(args)
	var out []string
	for _, a := range args {
		if strings.Contains(a, "...") {
			if build.IsLocalImport(a) {
				out = append(out, allPackagesInFS(a)...)
			} else {
				out = append(out, allPackages(a)...)
			}
			continue
		}
		out = append(out, a)
	}
	return out
}
273451
func appendImports(i, a []*ImportSpec) []*ImportSpec {
	for _, v := range a {
		contains := false
		for _, att := range i {
			if att.Path == v.Path {
				contains = true
				break
			}
		}
		if contains != true {
			i = append(i, v)
		}
	}
	return i
}
571114
func GetMapDiff(map1, map2 map[string]PackageInfo) PackageDiff {
	diff := diffMaps(map1, map2)
	diffVal := reflect.ValueOf(diff)
	packDiff := diffVal.Interface().(PackageDiff)
	return packDiff
}
79666
func (g *Generator) generateImports() {
	imports := make(map[GoImportPath]GoPackageName)
	for i, s := range g.file.Dependency {
		fd := g.fileByName(s)
		importPath := fd.importPath
		// Do not import our own package.
		if importPath == g.file.importPath {
			continue
		}
		// Do not import weak imports.
		if g.weak(int32(i)) {
			continue
		}
		// Do not import a package twice.
		if _, ok := imports[importPath]; ok {
			continue
		}
		// We need to import all the dependencies, even if we don't reference them,
		// because other code and tools depend on having the full transitive closure
		// of protocol buffer types in the binary.
		packageName := g.GoPackageName(importPath)
		if _, ok := g.usedPackages[importPath]; !ok {
			packageName = "_"
		}
		imports[importPath] = packageName
	}
	for importPath := range g.addedImports {
		imports[importPath] = g.GoPackageName(importPath)
	}
	// We almost always need a proto import.  Rather than computing when we
	// do, which is tricky when there's a plugin, just import it and
	// reference it later. The same argument applies to the fmt and math packages.
	g.P("import (")
	g.P(g.Pkg["fmt"] + ` "fmt"`)
	g.P(g.Pkg["math"] + ` "math"`)
	g.P(g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
	for importPath, packageName := range imports {
		g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
	}
	g.P(")")
	g.P()
	// TODO: may need to worry about uniqueness across plugins
	for _, p := range plugins {
		p.GenerateImports(g.file)
		g.P()
	}
	g.P("// Reference imports to suppress errors if they are not otherwise used.")
	g.P("var _ = ", g.Pkg["proto"], ".Marshal")
	g.P("var _ = ", g.Pkg["fmt"], ".Errorf")
	g.P("var _ = ", g.Pkg["math"], ".Inf")
	g.P()
}