Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2957)

Delta Between Two Patch Sets: src/cmd/gofix/fix.go

Issue 5448088: code review 5448088: cmd: shorten composite literal field values (Closed)
Left Patch Set: Created 12 years, 3 months ago
Right Patch Set: diff -r f91f50b96e10 https://go.googlecode.com/hg/ Created 12 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(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
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: {
gri 2011/12/02 23:11:05 I'd leave this file alone - no real win
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
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b