Refactoring

492 views
Skip to first unread message

Max

unread,
Jul 5, 2012, 12:15:38 PM7/5/12
to golan...@googlegroups.com
I have big go file 1500 lines and I have to uppercase 30+ fields in 5 structs to enable serilization
It may take hour or two to fix.

Is there some command line refactoring tool to rename fields and names like in Java (eclipse, netbeans)
I seen that golang has structs to parse go files.
I expect it should be some refactoring 

Aram Hăvărneanu

unread,
Jul 5, 2012, 12:27:25 PM7/5/12
to Max, golan...@googlegroups.com
Sorry, go/ast does not currently do type analysis, so it's impossible
to use it to rename struct fields and methods, only functions. There's
exp/types which should do the necessary type analysis, but I haven't
used it yet so I don't know how mature it is.

--
Aram Hăvărneanu

Max

unread,
Jul 5, 2012, 12:38:01 PM7/5/12
to golan...@googlegroups.com
It would be great to have such tool.
I have finished renaming. It took less time because account.Data is always account.Data but not this->Data or Data
Very wise idea to not use this pointer 

Jim Whitehead II

unread,
Jul 5, 2012, 1:27:25 PM7/5/12
to Max, golan...@googlegroups.com
You can always use gofmt's -r switch, you can do something like this:

gofmt -r 'a.data -> a.Data'

It turns out to be a really powerful tool.

- Jim

Max

unread,
Jul 5, 2012, 5:25:06 PM7/5/12
to golan...@googlegroups.com, Max
Thank You!
Is it more intelligent then replace feature of regular text editor?
Help tells it is rewrite. 
Reply all
Reply to author
Forward
0 new messages