| // Copyright 2011 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| `Adapt image.NewXxx calls to pass an image.Rectangle instead of (w, h int). |
| http://codereview.appspot.com/4964073 |
| var imagenewFuncs = map[string]bool{ |
| func imagenew(f *ast.File) bool { |
| if !imports(f, "image") { |
| walk(f, func(n interface{}) { |
| call, ok := n.(*ast.CallExpr) |
| for newFunc := range imagenewFuncs { |
| if len(call.Args) == 2 && isPkgDot(call.Fun, "image", newFunc) { |
| if len(call.Args) == 3 && isPkgDot(call.Fun, "image", "NewPaletted") { |
| // Replace image.NewXxx(w, h) with image.NewXxx(image.Rect(0, 0, w, h)). |
| &ast.BasicLit{Value: "0"}, |
| &ast.BasicLit{Value: "0"}, |
| rectArgs = append(rectArgs, call.Args[:2]...) |
| call.Args = append(rect, call.Args[2:]...) |