// 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.
197009
func defaultGoPackageName(f *descriptor.FileDescriptorProto) string {
	name := packageIdentityName(f)
	return strings.Replace(name, ".", "_", -1)
}
471096
func (p PackageInfo) PackageName() string {
	parts := strings.Split(p.ComputedPackage, ".")
	return parts[len(parts)-1]
}
689955
func (w *Wrapper) allPackagesInOrder() []*PackageInfo {
	result := make([]*PackageInfo, 0, len(w.allPackages))
	names := make([]string, 0, len(w.allPackages))
	for name := range w.allPackages {
		names = append(names, name)
	}
	sort.Strings(names)
	for _, name := range names {
		result = append(result, w.allPackages[name])
	}
	return result
}
65053
func DefaultImportPathToName(path, srcDir string) (string, error) {
	if path == "C" {
		return "C", nil
	}
	pkg, err := build.Default.Import(path, srcDir, 0)
	return pkg.Name, err
}
801759
func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package, manualMap defaulterFuncMap) {
	buffer := &bytes.Buffer{}
	sw := generator.NewSnippetWriter(buffer, context, "$", "$")

	for _, f := range pkg.Functions {
		if f.Underlying == nil || f.Underlying.Kind != types.Func {
			klog.Errorf("Malformed function: %#v", f)
			continue
		}
		if f.Underlying.Signature == nil {
			klog.Errorf("Function without signature: %#v", f)
			continue
		}
		signature := f.Underlying.Signature
		// Check whether the function is defaulting function.
		// Note that all of them have signature:
		// object: func SetObjectDefaults_inType(*inType)
		// base: func SetDefaults_inType(*inType)
		// additional: func SetDefaults_inType_Qualifier(*inType)
		if signature.Receiver != nil {
			continue
		}
		if len(signature.Parameters) != 1 {
			continue
		}
		if len(signature.Results) != 0 {
			continue
		}
		inType := signature.Parameters[0]
		if inType.Kind != types.Pointer {
			continue
		}
		// Check if this is the primary defaulter.
		args := defaultingArgsFromType(inType.Elem)
		sw.Do("$.inType|defaultfn$", args)
		switch {
		case f.Name.Name == buffer.String():
			key := inType.Elem
			// We might scan the same package twice, and that's OK.
			v, ok := manualMap[key]
			if ok && v.base != nil && v.base.Name.Package != pkg.Path {
				panic(fmt.Sprintf("duplicate static defaulter defined: %#v", key))
			}
			v.base = f
			manualMap[key] = v
			klog.V(6).Infof("found base defaulter function for %s from %s", key.Name, f.Name)
		// Is one of the additional defaulters - a top level defaulter on a type that is
		// also invoked.
		case strings.HasPrefix(f.Name.Name, buffer.String()+"_"):
			key := inType.Elem
			v, ok := manualMap[key]
			if ok {
				exists := false
				for _, existing := range v.additional {
					if existing.Name == f.Name {
						exists = true
						break
					}
				}
				if exists {
					continue
				}
			}
			v.additional = append(v.additional, f)
			manualMap[key] = v
			klog.V(6).Infof("found additional defaulter function for %s from %s", key.Name, f.Name)
		}
		buffer.Reset()
		sw.Do("$.inType|objectdefaultfn$", args)
		if f.Name.Name == buffer.String() {
			key := inType.Elem
			// We might scan the same package twice, and that's OK.
			v, ok := manualMap[key]
			if ok && v.base != nil && v.base.Name.Package != pkg.Path {
				panic(fmt.Sprintf("duplicate static defaulter defined: %#v", key))
			}
			v.object = f
			manualMap[key] = v
			klog.V(6).Infof("found object defaulter function for %s from %s", key.Name, f.Name)
		}
		buffer.Reset()
	}
}
398242
func (s *DeploymentLaunchConfig) SetPackageName(v string) *DeploymentLaunchConfig {
	s.PackageName = &v
	return s
}
1116987
func (p Packet) Name() (name string) {
	// todo: think of ways to make this not a compiled in hack
	// todo: collectd 4 uses different patterns for some plugins
	// https://collectd.org/wiki/index.php/V4_to_v5_migration_guide
	switch p.Plugin {
	case "df":
		name = fmt.Sprintf("df_%s_%s", p.PluginInstance, p.TypeInstance)
	case "interface":
		name = fmt.Sprintf("%s_%s", p.Type, p.PluginInstance)
	case "load":
		name = "load"
	case "memory":
		name = fmt.Sprintf("memory_%s", p.TypeInstance)
	default:
		name = fmt.Sprintf("%s_%s_%s_%s", p.Plugin, p.PluginInstance, p.Type, p.TypeInstance)
	}
	return name
}
93115
func packageFilenameLine(ld *LineData, depth int) {
	i, filename, linenum, ok := runtime.Caller(depth)
	if !ok {
		return
	}

	// Strip the directory from the filename. Even on Windows this is slash
	// delimited. See https://github.com/golang/go/issues/3335.
	fileParts := strings.Split(filename, "/")
	ld.SourceFile = fileParts[len(fileParts)-1]
	ld.SourceLine = linenum

	// Set up params from the call stack.
	f := runtime.FuncForPC(i)
	if f == nil {
		return
	}

	// generate the separate package name and function name
	packagePath := strings.Split(f.Name(), "/")
	n := len(packagePath)
	pkgFunc := strings.SplitN(packagePath[n-1], ".", 2)
	if len(pkgFunc) != 2 {
		return
	}

	pkg := strings.Join(packagePath[:n-1], "/") + fmt.Sprintf("/%s", pkgFunc[0])
	ld.CallingPackage = pkg
	ld.CallingFunction = pkgFunc[1]
}
971822
func (l *LanguageOpts) ManglePackageName(name, suffix string) string {
	if name == "" {
		return suffix
	}
	pth := filepath.ToSlash(filepath.Clean(name)) // preserve path
	_, pkg := path.Split(pth)                     // drop path
	return l.MangleName(swag.ToFileName(pkg), suffix)
}
1121554
func packageWithName(name string) (pkg *build.Package, err error) {
	pkg, err = build.Default.Import(name, ".", build.ImportMode(0))
	if err == nil {
		return
	}

	pkg, err = build.Default.Import(name, ".", build.ImportMode(1))
	return
}
1197569
func (s *ModelPackageSummary) SetModelPackageName(v string) *ModelPackageSummary {
	s.ModelPackageName = &v
	return s
}
1054981
func (v *GenerateServiceRequest) GetPackagePrefix() (o string) {
	if v != nil {
		o = v.PackagePrefix
	}
	return
}
1164872
func (r *rawNamer) Name(t *types.Type) string {
	if r.Names == nil {
		r.Names = Names{}
	}
	if name, ok := r.Names[t]; ok {
		return name
	}
	if t.Name.Package != "" {
		var name string
		if r.tracker != nil {
			r.tracker.AddType(t)
			if t.Name.Package == r.pkg {
				name = t.Name.Name
			} else {
				name = r.tracker.LocalNameOf(t.Name.Package) + "." + t.Name.Name
			}
		} else {
			if t.Name.Package == r.pkg {
				name = t.Name.Name
			} else {
				name = filepath.Base(t.Name.Package) + "." + t.Name.Name
			}
		}
		r.Names[t] = name
		return name
	}
	var name string
	switch t.Kind {
	case types.Builtin:
		name = t.Name.Name
	case types.Map:
		name = "map[" + r.Name(t.Key) + "]" + r.Name(t.Elem)
	case types.Slice:
		name = "[]" + r.Name(t.Elem)
	case types.Pointer:
		name = "*" + r.Name(t.Elem)
	case types.Struct:
		elems := []string{}
		for _, m := range t.Members {
			elems = append(elems, m.Name+" "+r.Name(m.Type))
		}
		name = "struct{" + strings.Join(elems, "; ") + "}"
	case types.Chan:
		// TODO: include directionality
		name = "chan " + r.Name(t.Elem)
	case types.Interface:
		// TODO: add to name test
		elems := []string{}
		for _, m := range t.Methods {
			// TODO: include function signature
			elems = append(elems, m.Name.Name)
		}
		name = "interface{" + strings.Join(elems, "; ") + "}"
	case types.Func:
		// TODO: add to name test
		params := []string{}
		for _, pt := range t.Signature.Parameters {
			params = append(params, r.Name(pt))
		}
		results := []string{}
		for _, rt := range t.Signature.Results {
			results = append(results, r.Name(rt))
		}
		name = "func(" + strings.Join(params, ",") + ")"
		if len(results) == 1 {
			name += " " + results[0]
		} else if len(results) > 1 {
			name += " (" + strings.Join(results, ",") + ")"
		}
	default:
		name = "unnameable_" + string(t.Kind)
	}
	r.Names[t] = name
	return name
}
979357
func Packages(_ *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
	boilerplate, err := arguments.LoadGoBoilerplate()
	if err != nil {
		klog.Fatalf("Failed loading boilerplate: %v", err)
	}

	return generator.Packages{&generator.DefaultPackage{
		PackageName: "sets",
		PackagePath: arguments.OutputPackagePath,
		HeaderText:  boilerplate,
		PackageDocumentation: []byte(
			`// Package sets has auto-generated set types.
`),
		// GeneratorFunc returns a list of generators. Each generator makes a
		// single file.
		GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
			generators = []generator.Generator{
				// Always generate a "doc.go" file.
				generator.DefaultGen{OptionalName: "doc"},
				// Make a separate file for the Empty type, since it's shared by every type.
				generator.DefaultGen{
					OptionalName: "empty",
					OptionalBody: []byte(emptyTypeDecl),
				},
			}
			// Since we want a file per type that we generate a set for, we
			// have to provide a function for this.
			for _, t := range c.Order {
				generators = append(generators, &genSet{
					DefaultGen: generator.DefaultGen{
						// Use the privatized version of the
						// type name as the file name.
						//
						// TODO: make a namer that converts
						// camelCase to '-' separation for file
						// names?
						OptionalName: c.Namers["private"].Name(t),
					},
					outputPackage: arguments.OutputPackagePath,
					typeToMatch:   t,
					imports:       generator.NewImportTracker(),
				})
			}
			return generators
		},
		FilterFunc: func(c *generator.Context, t *types.Type) bool {
			// It would be reasonable to filter by the type's package here.
			// It might be necessary if your input directory has a big
			// import graph.
			switch t.Kind {
			case types.Map, types.Slice, types.Pointer:
				// These types can't be keys in a map.
				return false
			case types.Builtin:
				return true
			case types.Struct:
				// Only some structs can be keys in a map. This is triggered by the line
				// // +genset
				// or
				// // +genset=true
				return extractBoolTagOrDie("genset", t.CommentLines) == true
			}
			return false
		},
	}}
}
343860
func (p *parser) parsePackage(fileNames []string) error {
	if len(fileNames) == 0 {
		return fmt.Errorf("fileNames is empty")
	}
	for i, name := range fileNames {
		if i > 0 && filepath.Dir(name) != filepath.Dir(fileNames[0]) {
			return fmt.Errorf("Go files belong to different directories")
		}
		if !strings.HasSuffix(name, ".go") {
			continue
		}
		file, err := goparser.ParseFile(p.fileSet, name, nil, 0)
		if err != nil {
			return fmt.Errorf("parsing %s: %s", name, err)
		}
		if len(p.files) > 0 && file.Name.Name != p.files[0].Name.Name {
			return fmt.Errorf("Go files belong to different packages")
		}
		p.files = append(p.files, file)
	}
	if len(p.files) == 0 {
		return fmt.Errorf("no buildable Go files")
	}
	return nil
}
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
}
437825
func (g *Generator) SetPackageName(name string) {
	g.packageName = name
	g.SetVar("packageName", name)
}