~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/cmd/gofix/sortslice.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

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(fix{
 
13
                "sortslice",
 
14
                sortslice,
 
15
                `Adapt code from sort.[Float64|Int|String]Array to  sort.[Float64|Int|String]Slice.
 
16
                
 
17
http://codereview.appspot.com/4602054
 
18
http://codereview.appspot.com/4639041
 
19
`,
 
20
        })
 
21
}
 
22
 
 
23
 
 
24
func sortslice(f *ast.File) (fixed bool) {
 
25
        if !imports(f, "sort") {
 
26
                return
 
27
        }
 
28
 
 
29
        walk(f, func(n interface{}) {
 
30
                s, ok := n.(*ast.SelectorExpr)
 
31
                if !ok || !isTopName(s.X, "sort") {
 
32
                        return
 
33
                }
 
34
 
 
35
                switch s.Sel.String() {
 
36
                case "Float64Array":
 
37
                        s.Sel.Name = "Float64Slice"
 
38
                case "IntArray":
 
39
                        s.Sel.Name = "IntSlice"
 
40
                case "StringArray":
 
41
                        s.Sel.Name = "StringSlice"
 
42
                default:
 
43
                        return
 
44
                }
 
45
 
 
46
                fixed = true
 
47
        })
 
48
 
 
49
        return
 
50
}