• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Renaming class references and variables

I have a list of class references(150) and variables(120) which I need to change. Can anyone tell me a way of doing this without refactoring 270 times? (I need this to be a repeatable process for testing and converting different source that uses same references and variables).

An additional problem is that to refactor a class reference is not allowed in eclipse so from what I can see I will have to replace the jar of classes and get hold of the source files (time lag involved) create a new package, import the classes and refactor the classes (which eclipse does allow) which in turn would rename the class references. If there is an alternative way please let me know.

I have explored an option of using the latest eclipse stable build (3.2) which allows scripting of refactor operations previously performed. That way I could painfully do 270 refactors but then run as one script for future testing and source that needs converting.  

I'm open to all options. so don't feel it has to all take place using eclipse.
thanks.
0
codemonkey156
Asked:
codemonkey156
  • 5
  • 4
  • 2
  • +1
3 Solutions
 
CEHJCommented:
>>is that to refactor a class reference is not allowed in eclipse so from what I can see

Not sure what you mean

private X x


on the selected 'x'

Alt+shift + R
0
 
objectsCommented:
you could try doing a global replace on all the files, and then manually going thru and fixing any problems that may occur.
0
 
codemonkey156Author Commented:
to answer CEHJ,

Alt+shift+R is correct in what I am trying to perform. Examples of code where this is not allowed

private A_A_A_V_v vAAA;
// where I'm trying to change all occurances A_A_A_V_v to Z_Z_Z_V_v

B_B_T_v vBBT = new B_B_T_v();
// where I'm trying to change all occurances B_B_T_v() to Y_Y_T_v()


to answer objects,

global replace does work more straightforwardly than refactor but there looks to be no option to automate the 270 separate changes that refactor scripts looks to offer.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
objectsCommented:
you could try some of these to see if any offered what u need

http://www.refactoring.com/tools.html
0
 
CEHJCommented:
>>// where I'm trying to change all occurances A_A_A_V_v to Z_Z_Z_V_v

You just rename the type A_A_A_V_v in the package explorer. The references will be updated automatically
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You would still need to do that individually for every distinct variable that you want to rename.
0
 
codemonkey156Author Commented:

>>You just rename the type A_A_A_V_v in the package explorer. The references will be updated automatically

This is what I was meaning in the 2nd paragraph of my original question. This looks therefore like it is the only way to do a class reference update. I will go and search for the source that the references refer to so this can happen as currently I've only be supplied the class files.

I've come across a problem with refactor rename of fActnCd

vAVariableName.fActnCd.map(new AbfString("KEYLISTENER"));

 I can see that a global replace would work but that will be no use for repetetive execution. Is there a way to refactor?
0
 
CEHJCommented:
You certainly can't rename stuff without the source.

>>I can see that a global replace would work but that will be no use for repetetive execution

Not quite sure what you mean by that
0
 
codemonkey156Author Commented:
Sorry, I'll clarify:

I have many lines of code in the following format with different names:
vAVariableName.fActnCd.map(new AbfString("KEYLISTENER"));

I want to change 'fActnCd' to 'fActCode'.

I can see I could change this for all code in my project by choosing  Ctrl-H then FILE SEARCH type 'fActnCd' click REPLACE type in the replace with box 'ActCode' then click REPLACE ALL.

Although this works for one rename, I'm not able to record a number of different replace's in a script. All the replaces need to be in a script so the process of replacing only takes hours the first time. All successive replaces for future code imports and replaces should take a minute.

I've discovered that a refactor script in eclipse 3.2 Stable Build offers a way to automate renaming. Although, when I select code to change, eg:  'fActnCd' and click REFACTOR then RENAME a message comes up which explains that only methods and variables can be renamed.

I think that a global replace would work best but how could I have it as a repeatable process like the refactor script?



0
 
CEHJCommented:
0
 
CEHJCommented:
:-)
0
 
codemonkey156Author Commented:
I ended up importing the source classes and then manually:

 Ctrl-H then FILE SEARCH type <class or variable to be translated> click REPLACE type in the replace with box <new class or variable name> then click REPLACE ALL.

After a hundred plus times, the translation was complete. I'll just hope that I'll not be asked to do it again

I've split the points on effort
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now