~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/cmd/fix/imagecolor.go

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
4
 
 
5
 
package main
6
 
 
7
 
import (
8
 
        "go/ast"
9
 
)
10
 
 
11
 
func init() {
12
 
        register(imagecolorFix)
13
 
}
14
 
 
15
 
var imagecolorFix = fix{
16
 
        "imagecolor",
17
 
        "2011-10-04",
18
 
        imagecolor,
19
 
        `Adapt code to types moved from image to color.
20
 
 
21
 
http://codereview.appspot.com/5132048
22
 
`,
23
 
}
24
 
 
25
 
var colorRenames = []struct{ in, out string }{
26
 
        {"Color", "Color"},
27
 
        {"ColorModel", "Model"},
28
 
        {"ColorModelFunc", "ModelFunc"},
29
 
        {"PalettedColorModel", "Palette"},
30
 
 
31
 
        {"RGBAColor", "RGBA"},
32
 
        {"RGBA64Color", "RGBA64"},
33
 
        {"NRGBAColor", "NRGBA"},
34
 
        {"NRGBA64Color", "NRGBA64"},
35
 
        {"AlphaColor", "Alpha"},
36
 
        {"Alpha16Color", "Alpha16"},
37
 
        {"GrayColor", "Gray"},
38
 
        {"Gray16Color", "Gray16"},
39
 
 
40
 
        {"RGBAColorModel", "RGBAModel"},
41
 
        {"RGBA64ColorModel", "RGBA64Model"},
42
 
        {"NRGBAColorModel", "NRGBAModel"},
43
 
        {"NRGBA64ColorModel", "NRGBA64Model"},
44
 
        {"AlphaColorModel", "AlphaModel"},
45
 
        {"Alpha16ColorModel", "Alpha16Model"},
46
 
        {"GrayColorModel", "GrayModel"},
47
 
        {"Gray16ColorModel", "Gray16Model"},
48
 
}
49
 
 
50
 
func imagecolor(f *ast.File) (fixed bool) {
51
 
        if !imports(f, "image") {
52
 
                return
53
 
        }
54
 
 
55
 
        walk(f, func(n interface{}) {
56
 
                s, ok := n.(*ast.SelectorExpr)
57
 
 
58
 
                if !ok || !isTopName(s.X, "image") {
59
 
                        return
60
 
                }
61
 
 
62
 
                switch sel := s.Sel.String(); {
63
 
                case sel == "ColorImage":
64
 
                        s.Sel = &ast.Ident{Name: "Uniform"}
65
 
                        fixed = true
66
 
                case sel == "NewColorImage":
67
 
                        s.Sel = &ast.Ident{Name: "NewUniform"}
68
 
                        fixed = true
69
 
                default:
70
 
                        for _, rename := range colorRenames {
71
 
                                if sel == rename.in {
72
 
                                        addImport(f, "image/color")
73
 
                                        s.X.(*ast.Ident).Name = "color"
74
 
                                        s.Sel.Name = rename.out
75
 
                                        fixed = true
76
 
                                }
77
 
                        }
78
 
                }
79
 
        })
80
 
 
81
 
        if fixed && !usesImport(f, "image") {
82
 
                deleteImport(f, "image")
83
 
        }
84
 
        return
85
 
}