From 76567ab6392f57e64d0b7438ab52304e234fb525 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Fri, 3 Jun 2016 23:26:15 +1000 Subject: [PATCH] Fix imports for Go 1.5+ Particularly important for 1.6+, since the deprecated imports have been removed entirely. Fixed by syncing with upstream stringer (includes some other minor fixes/modifications). --- stringer.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stringer.go b/stringer.go index df4cbbc..efd2fbd 100644 --- a/stringer.go +++ b/stringer.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build go1.5 + // Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer // interface. Given the name of a (signed or unsigned) integer type T that has constants // defined, stringer will create a new self-contained Go source file implementing @@ -64,20 +66,18 @@ import ( "fmt" "go/ast" "go/build" + exact "go/constant" "go/format" + "go/importer" "go/parser" "go/token" + "go/types" "io/ioutil" "log" "os" "path/filepath" "sort" "strings" - - "golang.org/x/tools/go/exact" - "golang.org/x/tools/go/types" - - _ "golang.org/x/tools/go/gcimporter" ) var ( @@ -90,7 +90,7 @@ var ( func Usage() { fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) fmt.Fprintf(os.Stderr, "\tstringer [flags] -type T [directory]\n") - fmt.Fprintf(os.Stderr, "\tstringer [flags[ -type T files... # Must be a single package\n") + fmt.Fprintf(os.Stderr, "\tstringer [flags] -type T files... # Must be a single package\n") fmt.Fprintf(os.Stderr, "For more information, see:\n") fmt.Fprintf(os.Stderr, "\thttp://godoc.org/golang.org/x/tools/cmd/stringer\n") fmt.Fprintf(os.Stderr, "Flags:\n") @@ -129,7 +129,7 @@ func main() { } // Print the header and package clause. - g.Printf("// Code generated by \"stringer %s\"; DO NOT EDIT\n", strings.Join(os.Args[1:], " ")) + g.Printf("// Code generated by \"enumer %s\"; DO NOT EDIT\n", strings.Join(os.Args[1:], " ")) g.Printf("\n") g.Printf("package %s", g.pkg.name) g.Printf("\n") @@ -264,7 +264,7 @@ func (g *Generator) parsePackage(directory string, names []string, text interfac // check type-checks the package. The package must be OK to proceed. func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) { pkg.defs = make(map[*ast.Ident]types.Object) - config := types.Config{FakeImportC: true} + config := types.Config{Importer: importer.Default(), FakeImportC: true} info := &types.Info{ Defs: pkg.defs, }