Commit 69905c62 authored by Robert Hencke's avatar Robert Hencke Committed by Rob Pike

gofix: fixes for sort changes

Fixes #1969.

R=gri, rsc, r
CC=golang-dev
https://golang.org/cl/4634076
parent f70e8ed0
......@@ -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
......
// 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
}
// 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
`,
},
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment