]> Cypherpunks repositories - gostls13.git/commitdiff
gofix: fixes for sort changes
authorRobert Hencke <robert.hencke@gmail.com>
Sat, 25 Jun 2011 22:48:53 +0000 (08:48 +1000)
committerRob Pike <r@golang.org>
Sat, 25 Jun 2011 22:48:53 +0000 (08:48 +1000)
Fixes #1969.

R=gri, rsc, r
CC=golang-dev
https://golang.org/cl/4634076

src/cmd/gofix/Makefile
src/cmd/gofix/sortslice.go [new file with mode: 0644]
src/cmd/gofix/sortslice_test.go [new file with mode: 0644]

index b157649e873eb6f59391e1969bbdc4bed5c389f3..60035e65e08d114204d6c6fb0014daa701bed230 100644 (file)
@@ -7,15 +7,16 @@ include ../../Make.inc
 TARG=gofix
 GOFILES=\
        fix.go\
-       netdial.go\
-       main.go\
-       oserrorstring.go\
-       osopen.go\
        httpfinalurl.go\
        httpheaders.go\
        httpserver.go\
+       main.go\
+       netdial.go\
+       oserrorstring.go\
+       osopen.go\
        procattr.go\
        reflect.go\
+       sortslice.go\
        typecheck.go\
 
 include ../../Make.cmd
diff --git a/src/cmd/gofix/sortslice.go b/src/cmd/gofix/sortslice.go
new file mode 100644 (file)
index 0000000..b9c108b
--- /dev/null
@@ -0,0 +1,50 @@
+// 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.
+
+package main
+
+import (
+       "go/ast"
+)
+
+func init() {
+       register(fix{
+               "sortslice",
+               sortslice,
+               `Adapt code from sort.[Float64|Int|String]Array to  sort.[Float64|Int|String]Slice.
+               
+http://codereview.appspot.com/4602054
+http://codereview.appspot.com/4639041
+`,
+       })
+}
+
+
+func sortslice(f *ast.File) (fixed bool) {
+       if !imports(f, "sort") {
+               return
+       }
+
+       walk(f, func(n interface{}) {
+               s, ok := n.(*ast.SelectorExpr)
+               if !ok || !isTopName(s.X, "sort") {
+                       return
+               }
+
+               switch s.Sel.String() {
+               case "Float64Array":
+                       s.Sel.Name = "Float64Slice"
+               case "IntArray":
+                       s.Sel.Name = "IntSlice"
+               case "StringArray":
+                       s.Sel.Name = "StringSlice"
+               default:
+                       return
+               }
+
+               fixed = true
+       })
+
+       return
+}
diff --git a/src/cmd/gofix/sortslice_test.go b/src/cmd/gofix/sortslice_test.go
new file mode 100644 (file)
index 0000000..404feb2
--- /dev/null
@@ -0,0 +1,35 @@
+// 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.
+
+package main
+
+func init() {
+       addTestCases(sortsliceTests)
+}
+
+var sortsliceTests = []testCase{
+       {
+               Name: "sortslice.0",
+               In: `package main
+
+import (
+       "sort"
+)
+
+var _ = sort.Float64Array
+var _ = sort.IntArray
+var _ = sort.StringArray
+`,
+               Out: `package main
+
+import (
+       "sort"
+)
+
+var _ = sort.Float64Slice
+var _ = sort.IntSlice
+var _ = sort.StringSlice
+`,
+       },
+}