// defaultGoPackageName returns the default go package name to be used for go files generated from "f".
// You might need to use an unique alias for the package when you import it.  Use ReserveGoPackageAlias to get a unique alias.
185409
func (r *Registry) defaultGoPackageName(f *descriptor.FileDescriptorProto) string {
	name := r.packageIdentityName(f)
	return sanitizePackageName(name)
}
256526
func extractPackageName(line string) (packageName, methodName string) {
	packagePath, packageNameAndFunction := splitAtLastSlash(line)
	parts := strings.Split(packageNameAndFunction, ".")
	packageName = parts[0]
	if len(packagePath) > 0 {
		packageName = fmt.Sprintf("%s/%s", packagePath, packageName)
	}
	methodName = strings.Join(parts[1:], ".")
	return
}
725211
func Default() types.Importer {
	return &customImporter{
		imported:      make(map[string]*types.Package),
		base:          importer.Default(),
		skipTestFiles: true,
	}
}
868985
func determinePackagePrefix(dir string) (string, error) {
	gopathList := os.Getenv("GOPATH")
	if gopathList == "" {
		return "", errors.New("$GOPATH is not set")
	}

	for _, gopath := range filepath.SplitList(gopathList) {
		packagePath, err := filepath.Rel(filepath.Join(gopath, "src"), dir)
		if err != nil {
			return "", err
		}

		// The match is valid only if it's within the directory tree.
		if !strings.HasPrefix(packagePath, "..") {
			return packagePath, nil
		}
	}

	return "", fmt.Errorf("directory %q is not inside $GOPATH/src", dir)
}
1197569
func (s *ModelPackageSummary) SetModelPackageName(v string) *ModelPackageSummary {
	s.ModelPackageName = &v
	return s
}
144512
func goFmtPackage(pkg *build.Package) {
	output, err := exec.Command("go", "fmt", pkg.ImportPath).Output()

	if err != nil {
		fmt.Printf("Warning: Error running 'go fmt %s'.\nstdout: %s\n%s\n", pkg.ImportPath, output, err.Error())
	}
}
1258484
func (g *Generator) defaultGoPackage() string {
	p := g.PackageImportPath
	if i := strings.LastIndex(p, "/"); i >= 0 {
		p = p[i+1:]
	}
	if p == "" {
		return ""
	}

	p = strings.Map(badToUnderscore, p)
	// Identifier must not be keyword: insert _.
	if isGoKeyword[p] {
		p = "_" + p
	}
	// Identifier must not begin with digit: insert _.
	if r, _ := utf8.DecodeRuneInString(p); unicode.IsDigit(r) {
		p = "_" + p
	}
	return p
}
1104750
func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
	if name, ok := g.packageNames[importPath]; ok {
		return name
	}
	name := cleanPackageName(baseName(string(importPath)))
	for i, orig := 1, name; g.usedPackageNames[name] || isGoPredeclaredIdentifier[string(name)]; i++ {
		name = orig + GoPackageName(strconv.Itoa(i))
	}
	g.packageNames[importPath] = name
	g.usedPackageNames[name] = true
	return name
}
635119
func (s *DeleteModelPackageInput) SetModelPackageName(v string) *DeleteModelPackageInput {
	s.ModelPackageName = &v
	return s
}
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
}
1053565
func (g *Generator) SetPackageNames() {
	// Register the name for this package.  It will be the first name
	// registered so is guaranteed to be unmodified.
	pkg, explicit := g.genFiles[0].goPackageName()

	// Check all files for an explicit go_package option.
	for _, f := range g.genFiles {
		thisPkg, thisExplicit := f.goPackageName()
		if thisExplicit {
			if !explicit {
				// Let this file's go_package option serve for all input files.
				pkg, explicit = thisPkg, true
			} else if thisPkg != pkg {
				g.Fail("inconsistent package names:", thisPkg, pkg)
			}
		}
	}

	// If we don't have an explicit go_package option but we have an
	// import path, use that.
	if !explicit {
		p := g.defaultGoPackage()
		if p != "" {
			pkg, explicit = p, true
		}
	}

	// If there was no go_package and no import path to use,
	// double-check that all the inputs have the same implicit
	// Go package name.
	if !explicit {
		for _, f := range g.genFiles {
			thisPkg, _ := f.goPackageName()
			if thisPkg != pkg {
				g.Fail("inconsistent package names:", thisPkg, pkg)
			}
		}
	}

	g.packageName = RegisterUniquePackageName(pkg, g.genFiles[0])

	// Register the support package names. They might collide with the
	// name of a package we import.
	g.Pkg = map[string]string{
		"fmt":          RegisterUniquePackageName("fmt", nil),
		"math":         RegisterUniquePackageName("math", nil),
		"proto":        RegisterUniquePackageName("proto", nil),
		"golang_proto": RegisterUniquePackageName("golang_proto", nil),
	}

AllFiles:
	for _, f := range g.allFiles {
		for _, genf := range g.genFiles {
			if f == genf {
				// In this package already.
				uniquePackageName[f.FileDescriptorProto] = g.packageName
				continue AllFiles
			}
		}
		// The file is a dependency, so we want to ignore its go_package option
		// because that is only relevant for its specific generated output.
		pkg := f.GetPackage()
		if pkg == "" {
			pkg = baseName(*f.Name)
		}
		RegisterUniquePackageName(pkg, f)
	}
}
912005
func (l *LanguageOpts) ManglePackagePath(name string, suffix string) string {
	if name == "" {
		return suffix
	}
	target := filepath.ToSlash(filepath.Clean(name)) // preserve path
	parts := strings.Split(target, "/")
	parts[len(parts)-1] = l.ManglePackageName(parts[len(parts)-1], suffix)
	return strings.Join(parts, "/")
}
269764
func functionName(fName string) (pack string, name string) {
	name = fName
	// We get this:
	//	runtime/debug.*T·ptrmethod
	// and want this:
	//  pack = runtime/debug
	//	name = *T.ptrmethod
	if idx := strings.LastIndex(name, "."); idx != -1 {
		pack = name[:idx]
		name = name[idx+1:]
	}
	name = strings.Replace(name, "·", ".", -1)
	return
}
509585
func defaultGoPath() string {
	gpDefault := build.Default.GOPATH
	gps := filepath.SplitList(gpDefault)

	return gps[0]
}
700511
func Default() *GeneratorArgs {
	return &GeneratorArgs{
		OutputBase:                 DefaultSourceTree(),
		GoHeaderFilePath:           filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"),
		GeneratedBuildTag:          "ignore_autogenerated",
		GeneratedByCommentTemplate: "// Code generated by GENERATOR_NAME. DO NOT EDIT.",
		defaultCommandLineFlags:    true,
	}
}
979599
func packageIdentityName(f *descriptor.FileDescriptorProto) string {
	if f.Options != nil && f.Options.GoPackage != nil {
		gopkg := f.Options.GetGoPackage()
		idx := strings.LastIndex(gopkg, "/")
		if idx < 0 {
			return gopkg
		}

		return gopkg[idx+1:]
	}

	if f.Package == nil {
		base := filepath.Base(f.GetName())
		ext := filepath.Ext(base)
		return strings.TrimSuffix(base, ext)
	}
	return f.GetPackage()
}
1068753
func (n Name) Package() string {
	key := string(n)

	for _, gp := range envy.GoPaths() {
		key = strings.TrimPrefix(key, filepath.Join(gp, "src"))
		key = strings.TrimPrefix(key, gp)
	}
	key = strings.TrimPrefix(key, string(filepath.Separator))

	key = strings.Replace(key, "\\", "/", -1)
	return key
}