The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Batch rename refactoring for IntelliJ IDEA

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marty Andrews

Posts: 190
Nickname: wry
Registered: Dec, 2003

Marty Andrews is an agile coach and developer for Thoughtworks Australia
Batch rename refactoring for IntelliJ IDEA Posted: Oct 25, 2006 8:24 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Marty Andrews.
Original Post: Batch rename refactoring for IntelliJ IDEA
Feed Title: Ramblings of the Wry Tradesman
Feed URL: http://www.wrytradesman.com/blog/index.rdf
Feed Description: Marty Andrews talks about the day to day issues he faces as an agile coach on large enterprise applications in Australia.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Marty Andrews
Latest Posts From Ramblings of the Wry Tradesman

Advertisement

I've recently joined an existing project that has about 200k lines of code already in it, with no consistent coding standard applied. We decided that we wanted to consistently apply an underscore prefix for names of instance variables in classes. A quick grep through the source code told me that there were about 12000 (yep - thats twelve thousand) cases that didn't conform to the standard. I didn't want to do all of them by hand. IntelliJ IDEA has a feature called "Structural Search and Replace", but that will leave me with broken code. I really want a "Structural Search and Refactor". That doesn't exist, so I figured I'd build one.

I used the "Stuctural Find" feature inside IntelliJ to find all instance fields of a class. The template for that exists already. I set the regular expression on the field name to be [a-z][a-zA-Z0-9]* to make sure I didn't pick up things that already had the underscore, and ticked the box saying "This variable is target of the search". After running that, I get my 12000 or so results in the find results window, and I can use a hotkey to navigate back and forth between them. My cursor appears right on the variable I want to rename.

At this stage, I have a sequence of keypresses I can use to refactor each variable name,

apple - alt - down# go to next misnamed variable
shift - F6# rename the variable
home# go to the start of the variable name
_# insert an underscore
enter# complete the refactoring
apple - S# save the file

I tried recording an IntelliJ macro to record the events, but unfortunately the macros don't work across modal dialogs. The rename refactoring pops one up, so that didn't work. Instead, I downloaded an OS keyboard macro tool called Keyboard Maestro. I put that sequence of keys into it and had it repeat every second while IntelliJ was active. I left it running overnight, and when I got up in the morning I had 12000 renamed variables that all conformed to our coding standard. Excellent!

Read: Batch rename refactoring for IntelliJ IDEA

Topic: Shhhh - No Vista Comparisons Previous Topic   Next Topic Topic: We are back

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use