MCPcopy Create free account
hub / github.com/golang/appengine / processFile

Function processFile

cmd/aefix/main.go:110–196  ·  view source on GitHub ↗
(filename string, useStdin bool)

Source from the content-addressed store, hash-verified

108}
109
110func processFile(filename string, useStdin bool) error {
111 var f *os.File
112 var err error
113 var fixlog bytes.Buffer
114
115 if useStdin {
116 f = os.Stdin
117 } else {
118 f, err = os.Open(filename)
119 if err != nil {
120 return err
121 }
122 defer f.Close()
123 }
124
125 src, err := ioutil.ReadAll(f)
126 if err != nil {
127 return err
128 }
129
130 file, err := parser.ParseFile(fset, filename, src, parserMode)
131 if err != nil {
132 return err
133 }
134
135 // Apply all fixes to file.
136 newFile := file
137 fixed := false
138 for _, fix := range fixes {
139 if allowed != nil && !allowed[fix.name] {
140 continue
141 }
142 if fix.f(newFile) {
143 fixed = true
144 fmt.Fprintf(&fixlog, " %s", fix.name)
145
146 // AST changed.
147 // Print and parse, to update any missing scoping
148 // or position information for subsequent fixers.
149 newSrc, err := gofmtFile(newFile)
150 if err != nil {
151 return err
152 }
153 newFile, err = parser.ParseFile(fset, filename, newSrc, parserMode)
154 if err != nil {
155 if debug {
156 fmt.Printf("%s", newSrc)
157 report(err)
158 os.Exit(exitCode)
159 }
160 return err
161 }
162 }
163 }
164 if !fixed {
165 return nil
166 }
167 fmt.Fprintf(os.Stderr, "%s: fixed %s\n", filename, fixlog.String()[1:])

Callers 2

mainFunction · 0.70
visitFileFunction · 0.70

Calls 6

gofmtFileFunction · 0.70
reportFunction · 0.70
diffFunction · 0.70
CloseMethod · 0.45
StringMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…