LEFT | RIGHT |
(no file at all) | |
| 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 "sorthelpers", |
| 14 sorthelpers, |
| 15 `Adapt code from sort.Sort[Ints|Float64s|Strings] to sort.[Ints|
Float64s|Strings]. |
| 16 `, |
| 17 }) |
| 18 } |
| 19 |
| 20 |
| 21 func sorthelpers(f *ast.File) (fixed bool) { |
| 22 if !imports(f, "sort") { |
| 23 return |
| 24 } |
| 25 |
| 26 walk(f, func(n interface{}) { |
| 27 s, ok := n.(*ast.SelectorExpr) |
| 28 if !ok || !isTopName(s.X, "sort") { |
| 29 return |
| 30 } |
| 31 |
| 32 switch s.Sel.String() { |
| 33 case "SortFloat64s": |
| 34 s.Sel.Name = "Float64s" |
| 35 case "SortInts": |
| 36 s.Sel.Name = "Ints" |
| 37 case "SortStrings": |
| 38 s.Sel.Name = "Strings" |
| 39 default: |
| 40 return |
| 41 } |
| 42 |
| 43 fixed = true |
| 44 }) |
| 45 |
| 46 return |
| 47 } |
LEFT | RIGHT |