MCPcopy Create free account
hub / github.com/decomp/decomp / usesImport

Function usesImport

cmd/go-post/fix.go:696–726  ·  view source on GitHub ↗
(f *ast.File, path string)

Source from the content-addressed store, hash-verified

694}
695
696func usesImport(f *ast.File, path string) (used bool) {
697 spec := importSpec(f, path)
698 if spec == nil {
699 return
700 }
701
702 name := spec.Name.String()
703 switch name {
704 case "<nil>":
705 // If the package name is not explicitly specified,
706 // make an educated guess. This is not guaranteed to be correct.
707 lastSlash := strings.LastIndex(path, "/")
708 if lastSlash == -1 {
709 name = path
710 } else {
711 name = path[lastSlash+1:]
712 }
713 case "_", ".":
714 // Not sure if this import is used - err on the side of caution.
715 return true
716 }
717
718 walk(f, func(n interface{}) {
719 sel, ok := n.(*ast.SelectorExpr)
720 if ok && isTopName(sel.X, name) {
721 used = true
722 }
723 })
724
725 return
726}
727
728func expr(s string) ast.Expr {
729 x, err := parser.ParseExpr(s)

Callers 1

renameFixTabFunction · 0.85

Calls 4

importSpecFunction · 0.85
walkFunction · 0.85
isTopNameFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected