MCPcopy
hub / github.com/golang/protobuf / GoPackageName

Method GoPackageName

protoc-gen-go/generator/generator.go:515–526  ·  view source on GitHub ↗

GoPackageName returns the name used for a package.

(importPath GoImportPath)

Source from the content-addressed store, hash-verified

513
514// GoPackageName returns the name used for a package.
515func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
516 if name, ok := g.packageNames[importPath]; ok {
517 return name
518 }
519 name := cleanPackageName(baseName(string(importPath)))
520 for i, orig := 1, name; g.usedPackageNames[name] || isGoPredeclaredIdentifier[string(name)]; i++ {
521 name = orig + GoPackageName(strconv.Itoa(i))
522 }
523 g.packageNames[importPath] = name
524 g.usedPackageNames[name] = true
525 return name
526}
527
528// AddImport adds a package to the generated file's import section.
529// It returns the name used for the package.

Callers 4

DefaultPackageNameMethod · 0.95
AddImportMethod · 0.95
generateImportsMethod · 0.95
generateImportedMethod · 0.95

Calls 3

cleanPackageNameFunction · 0.85
baseNameFunction · 0.85
GoPackageNameTypeAlias · 0.85

Tested by

no test coverage detected