Howardism Musings from my Awakening Dementia
My collected thoughts flamed by hubris
Home PageSend Comment

Eclipse Text Replacement

Often, when you are working with some code, you'll have a snippet that is the same, but needs to be changed slightly. My latest Grails project automatically creates a lot of scaffolding files, but those files need to be changed.

For instance:

def productionComplete = {
  boolean complete = params.doneProduction
  def yearlyData = getCurrentYearlyData()
  yearlyData.doneProduction = complete
  yearlyData.save()
}

Now, I need the exact same thing, but the production parts need to be energy and whatnot. But a straight-forward search and replace leaves you with:

def energyComplete =
{
  boolean complete = params.doneenergy   // Ack! This should be doneEnergy
  def yearlyData = getCurrentYearlyData()
  yearlyData.doneenergy = complete
  yearlyData.save()
}

With Eclipse (and some other editors), do a regular expression search and replace, and put a \C in front of the letters that should maintain their capitalization:

Screenshot from Eclipse

Which allows you to quickly hit the Replace/Find button a few times to get:

def energyComplete =
{
  boolean complete = params.doneEnergy
  def yearlyData = getCurrentYearlyData()
  yearlyData.doneEnergy = complete
  yearlyData.save()
}
Tell others about this article:
Click here to submit this page to Stumble It