mirror of
https://github.com/golang/go
synced 2024-11-24 18:10:02 -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:
parent
f70e8ed0f3
commit
69905c6213
@ -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
|
||||
|
50
src/cmd/gofix/sortslice.go
Normal file
50
src/cmd/gofix/sortslice.go
Normal 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
|
||||
}
|
35
src/cmd/gofix/sortslice_test.go
Normal file
35
src/cmd/gofix/sortslice_test.go
Normal 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
|
||||
`,
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user