LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 /* | 7 /* |
8 receiver named error | 8 receiver named error |
9 function named error | 9 function named error |
10 method on error | 10 method on error |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 return assigned | 467 return assigned |
468 } | 468 } |
469 | 469 |
470 // newPkgDot returns an ast.Expr referring to "pkg.name" at position pos. | 470 // newPkgDot returns an ast.Expr referring to "pkg.name" at position pos. |
471 func newPkgDot(pos token.Pos, pkg, name string) ast.Expr { | 471 func newPkgDot(pos token.Pos, pkg, name string) ast.Expr { |
472 return &ast.SelectorExpr{ | 472 return &ast.SelectorExpr{ |
473 X: &ast.Ident{ | 473 X: &ast.Ident{ |
474 NamePos: pos, | 474 NamePos: pos, |
475 Name: pkg, | 475 Name: pkg, |
476 }, | 476 }, |
477 » » Sel: &ast.Ident{ | 477 » » Sel: { |
478 NamePos: pos, | 478 NamePos: pos, |
479 Name: name, | 479 Name: name, |
480 }, | 480 }, |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 // renameTop renames all references to the top-level name old. | 484 // renameTop renames all references to the top-level name old. |
485 // It returns true if it makes any changes. | 485 // It returns true if it makes any changes. |
486 func renameTop(f *ast.File, old, new string) bool { | 486 func renameTop(f *ast.File, old, new string) bool { |
487 var fixed bool | 487 var fixed bool |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 } | 568 } |
569 | 569 |
570 // Determine name of import. | 570 // Determine name of import. |
571 // Assume added imports follow convention of using last element. | 571 // Assume added imports follow convention of using last element. |
572 _, name := path.Split(ipath) | 572 _, name := path.Split(ipath) |
573 | 573 |
574 // Rename any conflicting top-level references from name to name_. | 574 // Rename any conflicting top-level references from name to name_. |
575 renameTop(f, name, name+"_") | 575 renameTop(f, name, name+"_") |
576 | 576 |
577 newImport := &ast.ImportSpec{ | 577 newImport := &ast.ImportSpec{ |
578 » » Path: &ast.BasicLit{ | 578 » » Path: { |
579 Kind: token.STRING, | 579 Kind: token.STRING, |
580 Value: strconv.Quote(ipath), | 580 Value: strconv.Quote(ipath), |
581 }, | 581 }, |
582 } | 582 } |
583 | 583 |
584 // Find an import decl to add to. | 584 // Find an import decl to add to. |
585 var ( | 585 var ( |
586 bestMatch = -1 | 586 bestMatch = -1 |
587 lastImport = -1 | 587 lastImport = -1 |
588 impDecl *ast.GenDecl | 588 impDecl *ast.GenDecl |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 | 736 |
737 walk(f, func(n interface{}) { | 737 walk(f, func(n interface{}) { |
738 sel, ok := n.(*ast.SelectorExpr) | 738 sel, ok := n.(*ast.SelectorExpr) |
739 if ok && isTopName(sel.X, name) { | 739 if ok && isTopName(sel.X, name) { |
740 used = true | 740 used = true |
741 } | 741 } |
742 }) | 742 }) |
743 | 743 |
744 return | 744 return |
745 } | 745 } |
LEFT | RIGHT |