?
Solved

Renaming class references and variables

Posted on 2006-05-31
12
Medium Priority
?
208 Views
Last Modified: 2010-03-31
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
Comment
Question by:codemonkey156
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16796718
>>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
 
LVL 92

Assisted Solution

by:objects
objects earned 300 total points
ID: 16796758
you could try doing a global replace on all the files, and then manually going thru and fixing any problems that may occur.
0
 

Author Comment

by:codemonkey156
ID: 16797125
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 16797478
you could try some of these to see if any offered what u need

http://www.refactoring.com/tools.html
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 16797495
>>// 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
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 150 total points
ID: 16798770
You would still need to do that individually for every distinct variable that you want to rename.
0
 

Author Comment

by:codemonkey156
ID: 16799277

>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16800841
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
 

Author Comment

by:codemonkey156
ID: 16815326
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16815371
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16910225
:-)
0
 

Author Comment

by:codemonkey156
ID: 16910227
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question