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