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

Function renameFixTab

cmd/go-post/fix.go:793–834  ·  view source on GitHub ↗
(f *ast.File, tab []rename)

Source from the content-addressed store, hash-verified

791}
792
793func renameFixTab(f *ast.File, tab []rename) bool {
794 fixed := false
795 added := map[string]bool{}
796 check := map[string]bool{}
797 for _, t := range tab {
798 if !imports(f, t.OldImport) {
799 continue
800 }
801 optr, opkg, onam := parseName(t.Old)
802 walk(f, func(n interface{}) {
803 np, ok := n.(*ast.Expr)
804 if !ok {
805 return
806 }
807 x := *np
808 if optr {
809 p, ok := x.(*ast.StarExpr)
810 if !ok {
811 return
812 }
813 x = p.X
814 }
815 if !isPkgDot(x, opkg, onam) {
816 return
817 }
818 if t.NewImport != "" && !added[t.NewImport] {
819 addImport(f, t.NewImport)
820 added[t.NewImport] = true
821 }
822 *np = expr(t.New)
823 check[t.OldImport] = true
824 fixed = true
825 })
826 }
827
828 for ipath := range check {
829 if !usesImport(f, ipath) {
830 deleteImport(f, ipath)
831 }
832 }
833 return fixed
834}

Callers 1

renameFixFunction · 0.85

Calls 8

importsFunction · 0.85
parseNameFunction · 0.85
walkFunction · 0.85
isPkgDotFunction · 0.85
addImportFunction · 0.85
exprFunction · 0.85
usesImportFunction · 0.85
deleteImportFunction · 0.85

Tested by

no test coverage detected