http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/fix.go File src/cmd/gofix/fix.go (right): http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/fix.go#newcode66 src/cmd/gofix/fix.go:66: go1renameFix, Sync. David changed this around and this array ...
13 years, 4 months ago
(2011-11-03 22:38:14 UTC)
#2
http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/fix.go
File src/cmd/gofix/fix.go (right):
http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/fix.go#newcode66
src/cmd/gofix/fix.go:66: go1renameFix,
Sync. David changed this around and this array is gone.
http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/go1rename.go
File src/cmd/gofix/go1rename.go (right):
http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/go1rename.go#ne...
src/cmd/gofix/go1rename.go:63:
if !fixed {
return false
}
Otherwise, the renaming will happen even on code
that was already using the new imports.
http://codereview.appspot.com/5316078/diff/8001/src/cmd/gofix/go1rename.go#ne...
src/cmd/gofix/go1rename.go:71: if imp.Path.Value == rename.newPath {
I don't expect this to fire. Path.Value is a quoted string.
I think you want if importPath(imp) == rename.newPath.
The test is passing because isPkgRef does not handling
renamed imports correctly. If an import is renamed,
the parser knows that name, so the name can be resolved.
isTopName only recognizes unresolved names.
Another way to write this would be to drop this loop
and look for n.(*ast.SelectorExpr) in the walk,
and then check isTopName(sel.X) && sel.X.(*ast.Ident).Name == rename.old.
That's justified by something like
// This is old.Foo for an unresolved identifier old.
// Assume old refers to the package we renamed.
And then we could drop isPkgRef. We could keep it,
but implementing it to handle renames is a little harder.
It might also be good to move this up into the loop above.
If you just rewrote the import from old to new, then
that's the best time to do the rename. Could look
at the final element (path.Split) of the paths involved
instead of a separate table.
On Nov 3, 2011, at 3:38 PM, rsc@golang.org wrote: > > Another way to write ...
13 years, 4 months ago
(2011-11-04 00:13:49 UTC)
#3
On Nov 3, 2011, at 3:38 PM, rsc@golang.org wrote:
>
> Another way to write this would be to drop this loop
> and look for n.(*ast.SelectorExpr) in the walk,
> and then check isTopName(sel.X) && sel.X.(*ast.Ident).Name ==
> rename.old.
you don't mean isTopName(sel.X) but I'm not sure what you do mean.
-rob
On Thu, Nov 3, 2011 at 20:13, Rob 'Commander' Pike <r@google.com> wrote: > Another way ...
13 years, 4 months ago
(2011-11-04 00:17:35 UTC)
#4
On Thu, Nov 3, 2011 at 20:13, Rob 'Commander' Pike <r@google.com> wrote:
> Another way to write this would be to drop this loop
> and look for n.(*ast.SelectorExpr) in the walk,
> and then check isTopName(sel.X) && sel.X.(*ast.Ident).Name ==
> rename.old.
>
> you don't mean isTopName(sel.X) but I'm not sure what you do mean.
sorry, looks like i meant isTopName(sel.X, rename.old)
PTAL i think i wrote what you were asking, but you had a much more ...
13 years, 4 months ago
(2011-11-04 00:19:28 UTC)
#5
PTAL
i think i wrote what you were asking, but you had a much more complex
expression, which means either you misspoke or i misunderstood. the test passes
with this code.
i can refactor once i understand your approach.
-rob
On Nov 3, 2011, at 5:17 PM, Russ Cox wrote: > On Thu, Nov 3, ...
13 years, 4 months ago
(2011-11-04 00:20:00 UTC)
#6
On Nov 3, 2011, at 5:17 PM, Russ Cox wrote:
> On Thu, Nov 3, 2011 at 20:13, Rob 'Commander' Pike <r@google.com> wrote:
>> Another way to write this would be to drop this loop
>> and look for n.(*ast.SelectorExpr) in the walk,
>> and then check isTopName(sel.X) && sel.X.(*ast.Ident).Name ==
>> rename.old.
>>
>> you don't mean isTopName(sel.X) but I'm not sure what you do mean.
>
> sorry, looks like i meant isTopName(sel.X, rename.old)
right, but that's mostly the same as the rest of that line. see my CL.
Issue 5316078: code review 5316078: gofix: add go1pkgrename
(Closed)
Created 13 years, 4 months ago by r
Modified 13 years, 4 months ago
Reviewers:
Base URL:
Comments: 4