2

As a process of rebranding, we have a change the names in one of our huge project.

Is there a way that let me refactor my Java code base (rename class and package) programmatically using eclipse/other tools?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Kannan Ramamoorthy
  • 3,522
  • 6
  • 43
  • 60
  • To clarify, you are looking for an alternative to simply using Eclipse's **Refactor > Rename...** functionality? – skomisa Jun 15 '18 at 07:01
  • yes. Our project is a huge one with lots of packages and classes. Refactoring each and every class/package is not a scalable way. – Kannan Ramamoorthy Jun 15 '18 at 07:03
  • OK. So you have many names changes to be made to a huge project, and for logistic reasons you'd like them to be performed in a single pass if possible, rather than applying the changes one at a time? – skomisa Jun 15 '18 at 07:20
  • @skomisa yes. Imagining there could some programmatic way of doing it. – Kannan Ramamoorthy Jun 15 '18 at 07:22
  • Perhaps this fairly old SO post helps if you are interested in writing the code yourself: [How to programmatically rename a method using JDT](https://stackoverflow.com/questions/12968328/how-to-programmatically-rename-a-method-using-jdt) – skomisa Jun 15 '18 at 08:31

1 Answers1

1

Eclipse has a way of persisting refactorings that you apply into an XML file and gives you the possibility to replay this script later, see https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-refactoring.htm.

It is not that hard to write this script by hand, especially if you're just renaming code (refactoring within a method-body needs much more fine-grained information).

Volker Stolz
  • 7,055
  • 31
  • 48