func (p *PackageInfo) Rewrite() (first error) {
	codes, first := p.Format()
	if first != nil {
		return
	}
	for k, v := range codes {
		first = writeFile(k, v)
		if first != nil {
			return first
		}
	}
	return
}
Rewrite formats the package codes and writes to local loaderFiles.
package aster
import (
	"bytes"
	"fmt"
	"go/ast"
	"go/format"
	"go/token"
	"os"
	"path/filepath"
	"sort"
	"strings"
	"github.com/henrylee2cn/aster/tools"
	"github.com/henrylee2cn/goutil"
)
func (prog *Program) Format() (codes map[string]string, first error) {
	codes = make(map[string]string, 128)
	var c map[string]string
	for _, pkg := range prog.InitialPackages() {
		c, first = pkg.Format()
		if first != nil {
			return
		}
		for k, v := range c {
			codes[k] = v
		}
	}
	return
}
func (p *PackageInfo) Format() (codes map[string]string, first error) {
	codes = make(map[string]string, len(p.loaderFiles))
	var code string
	var codeBytes []byte
	pkgName := p.Pkg.Name()
	for _, f := range p.loaderFiles {
		code, first = p.FormatNode(f.File)
		if first != nil {
			return
		}
		code = tools.ChangePkgName(code, pkgName)
		codeBytes, first = tools.Format("", goutil.StringToBytes(code), nil)
		if first != nil {
			return
		}
		codes[f.Filename] = goutil.BytesToString(codeBytes)
	}
	return
}
func (f *File) Format() (codes map[string]string, first error) {
	codes = make(map[string]string, 1)
	code, first := f.PackageInfo.FormatNode(f.File)
	codes[f.Filename] = code
	return codes, first
}
func (prog *Program) FormatNode(node ast.Node) (string, error) {
	return formatNode(prog.fset, node)
}
func (p *PackageInfo) FormatNode(node ast.Node) (string, error) {
	return p.prog.FormatNode(node)
}
func (f *File) FormatNode(node ast.Node) (string, error) {
	return f.PackageInfo.FormatNode(node)
}
func formatNode(fset *token.FileSet, node ast.Node) (string, error) {
	var dst bytes.Buffer
	err := format.Node(&dst, fset, node)
	if err != nil {
		return "", err
	}
	return goutil.BytesToString(dst.Bytes()), nil
}
func (prog *Program) Rewrite() (first error) {
	for _, pkg := range prog.InitialPackages() {
		first = pkg.Rewrite()
		if first != nil {
			return
		}
	}
	return
}