~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/cmd/gofix/filepath.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
                "filepath",
 
14
                filepathFunc,
 
15
                `Adapt code from filepath.[List]SeparatorString to string(filepath.[List]Separator).
 
16
 
 
17
http://codereview.appspot.com/4527090
 
18
`,
 
19
        })
 
20
}
 
21
 
 
22
func filepathFunc(f *ast.File) (fixed bool) {
 
23
        if !imports(f, "path/filepath") {
 
24
                return
 
25
        }
 
26
 
 
27
        walk(f, func(n interface{}) {
 
28
                e, ok := n.(*ast.Expr)
 
29
                if !ok {
 
30
                        return
 
31
                }
 
32
 
 
33
                var ident string
 
34
                switch {
 
35
                case isPkgDot(*e, "filepath", "SeparatorString"):
 
36
                        ident = "filepath.Separator"
 
37
                case isPkgDot(*e, "filepath", "ListSeparatorString"):
 
38
                        ident = "filepath.ListSeparator"
 
39
                default:
 
40
                        return
 
41
                }
 
42
 
 
43
                // string(filepath.[List]Separator)
 
44
                *e = &ast.CallExpr{
 
45
                        Fun:  ast.NewIdent("string"),
 
46
                        Args: []ast.Expr{ast.NewIdent(ident)},
 
47
                }
 
48
 
 
49
                fixed = true
 
50
        })
 
51
 
 
52
        return
 
53
}