How to rename a lot of classes at once?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to rename a lot of classes at once?

tblanchard
I have a whole hierarchy of classes with some prefix AA.  I generated  
a clone of the hierarchy with a prefix like BB.

Now I am happy with the changes I've made to BBClass and want to  
replace the AAClass hierarchy with the BBClass hierarchy by deleting  
the AAClasses and renaming BBClasses to AAClasses.  This is my script:

| list bbDict |
list := AAClass withAllSubclasses asArray.
bbDict := Dictionary new.
list do: [:ea | bbDict at: ea bbClass put: ea name].
list do: [:cls | Smalltalk removeClass: cls].
bbDict keysAndValuesDo:[:k :v | Smalltalk renameClass: k as: v].

This doesn't seem to properly complete the job and leaves  
SystemDictionary and the new AAClasses in a weird state.

What am I missing?

-Todd Blanchard

Reply | Threaded
Open this post in threaded view
|

Re: How to rename a lot of classes at once?

Damien Cassou-3
Todd Blanchard a écrit :

> I have a whole hierarchy of classes with some prefix AA.  I generated a
> clone of the hierarchy with a prefix like BB.
>
> Now I am happy with the changes I've made to BBClass and want to replace
> the AAClass hierarchy with the BBClass hierarchy by deleting the
> AAClasses and renaming BBClasses to AAClasses.  This is my script:
>
> | list bbDict |
> list := AAClass withAllSubclasses asArray.
> bbDict := Dictionary new.
> list do: [:ea | bbDict at: ea bbClass put: ea name].
> list do: [:cls | Smalltalk removeClass: cls].
> bbDict keysAndValuesDo:[:k :v | Smalltalk renameClass: k as: v].
>
> This doesn't seem to properly complete the job and leaves
> SystemDictionary and the new AAClasses in a weird state.

Here is what I found in omnibrowser code.

To remove a class:
------------------

yourClass theNonMetaClass removeFromSystem.


To rename a class:
------------------

yourClass theNonMetaClass environment
     renameClassNamed: oldName as: newName asSymbol.


Browse obsolete references:
---------------------------

| binding |
binding := yourClass theNonMetaClass environment
                associationAt: aClassNode theNonMetaClass name.

(SystemNavigation default allCallsOn: binding) inspect


Hope this helps


Bye
       

Reply | Threaded
Open this post in threaded view
|

Re: How to rename a lot of classes at once?

Yanni Chiu
In reply to this post by tblanchard
Todd Blanchard wrote:
> I have a whole hierarchy of classes with some prefix AA.  I generated  a
> clone of the hierarchy with a prefix like BB.
>
> Now I am happy with the changes I've made to BBClass and want to  
> replace the AAClass hierarchy with the BBClass hierarchy by deleting  
> the AAClasses and renaming BBClasses to AAClasses.

How about:

- fileout your BB classes
- use an editor (the Squeak file browser for example)
   to search&replace BB with AA
- filein
- remove all your BB classes
- note: all the original AA instances will be migrated