Example #1
0
func objsMatch(pkg *grinder.Package, fn *ast.FuncDecl, pos token.Pos, objs []types.Object, start, end token.Pos) bool {
	for _, obj := range objs {
		if start < obj.Pos() && obj.Pos() < end {
			// declaration is in code being moved
			return true
		}
		if pkg.LookupAtPos(fn, pos, obj.Name()) != obj {
			if debug {
				println("OBJ MISMATCH", obj.Name(), pkg.LookupAtPos(fn, pos, obj.Name()), obj)
			}
			return false
		}
	}
	return true
}
Example #2
0
func grind(pkg *grinder.Package) {
	for _, name := range pkg.Filenames {
		if !pkg.Modified(name) {
			continue
		}

		if *diff {
			diffText, err := runDiff([]byte(pkg.OrigSrc(name)), []byte(pkg.Src(name)))
			if err != nil {
				ctxt.Errorf("%v", err)
			}
			os.Stdout.Write(diffText)
			continue
		}

		if err := ioutil.WriteFile(name, []byte(pkg.Src(name)), 0666); err != nil {
			ctxt.Errorf("%v", err)
		}
	}
}