1
0
mirror of https://github.com/golang/go synced 2024-11-24 20:50:11 -07:00

gofix: fixes for sort changes

Fixes #1969.

R=gri, rsc, r
CC=golang-dev
https://golang.org/cl/4634076
This commit is contained in:
Robert Hencke 2011-06-26 08:48:53 +10:00 committed by Rob Pike
parent f70e8ed0f3
commit 69905c6213
3 changed files with 90 additions and 4 deletions

View File

@ -7,15 +7,16 @@ include ../../Make.inc
TARG=gofix TARG=gofix
GOFILES=\ GOFILES=\
fix.go\ fix.go\
netdial.go\
main.go\
oserrorstring.go\
osopen.go\
httpfinalurl.go\ httpfinalurl.go\
httpheaders.go\ httpheaders.go\
httpserver.go\ httpserver.go\
main.go\
netdial.go\
oserrorstring.go\
osopen.go\
procattr.go\ procattr.go\
reflect.go\ reflect.go\
sortslice.go\
typecheck.go\ typecheck.go\
include ../../Make.cmd include ../../Make.cmd

View File

@ -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
}

View File

@ -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
`,
},
}