(f *ast.File, path string)
| 694 | } |
| 695 | |
| 696 | func 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 | |
| 728 | func expr(s string) ast.Expr { |
| 729 | x, err := parser.ParseExpr(s) |
no test coverage detected