the blog
Back to -Blog

ActionScript Refactoring: Renaming Classes

Automating class name changes
by Huw Collingbourne
Monday 15 June 2009.

The major new addition to the last beta of Amethyst was built-in refactoring. In previous blog posts, we’ve given an overview of some of the refactoring features such as ’encapsulating fields’ with the automatic creation of getter and setter methods and using Smart Tags with previewing...

We’ve already explained how to automate the renaming of functions and variables throughout a project. But Amethyst’s refactoring goes much further than this. One of its most powerful features is the ability to rename classes and update all references to those classes.

Let’s take a look at an example. Here I have a simple Flex-based adventure game. The visual design is defined in the file, Wombat.mxml, which, as you can see, also contains some ActionScript code...

Note that the code in Wombat.mxml creates objects from the Room class which is defined in a separate file, Room.as. You can see this file in the Solution Explorer, under the \Classes folder. Now I decide that I want to rename the ‘Room’ class to ‘Location’. To do this, I just go into the editor and change the class name...

When I start typing the new name a tiny red rectangle (a ‘Smart tag’) appears beneath the renamed class. When I click this tag, a menu pops down giving me the chance to rename the class immediately or preview the changes prior to renaming. I’ll just rename without previewing...

...and immediately, the Room class is transformed into the Location class. Note that the Amethyst refactoring has made a great many changes ‘behind the scenes’. For example, the constructor (public function Location()) has been changed to match the new class name. Since ActionScript requires that the file name should also match the class name, the file itself (as you can see in the Solution Explorer) has also been renamed (to Location.as). References to the Room class in other files in the project (here, for instance, in Wombat.mxml) have been modified to use the new class and constructor name. And finally, the IntelliSense system has been updated so that features such as code completion and ‘move to class’ via the navigation bar (see the item in the top-left drop-down list) have also been updated.

Refactoring is one of the major features of Amethyst Professional; beta 5 introduces just a few of the refactorings that will be in the final product. In fact, we have already added some new refactorings to the ‘edge’ (interim) release of Amethyst such as the ability to rename packages and move classes from one package to another as explained in another blog post.

We plan to add more refactoring capabilities soon so be sure to keep reading the blog for the latest developments.

Bookmark and Share   Keywords:  Amethyst  refactoring
© SapphireSteel Software 2014