the blog
Back to -Blog

Refactoring ActionScript: Moving Packages

Latest features of the Amethyst ’edge’ release
by Dermot Hogan
Tuesday 9 June 2009.

We’ve just put up a new mini-release of Amethyst on the download site. This is mainly to fix a problem with compiling large SWC projects but we’ve also added a nice new feature – the ability to move packages.

The problem with ActionScript (and Java) is that the location of a file and a package name must match. So if you have a package with a name like ‘x.y.x’ it must reside in a directory with the path (relative to the root of the project) ‘x\y\z’. In effect, the name of the package is connected to the physical storage location of the file. Now, I happen to think that this is a seriously dumb idea, though it does have the advantage of telling you where to look for a file from the source code. But then that’s what the Solution Explorer and Go to Definition do, rather more effectively in my view. Still, there are far worse things in ActionScript ... ‘hoisting’of variables anyone?

Anyway, the connection between the package name and the location of the package’s file makes changing the name or moving the file troublesome to say the least: if you change the name of a package, then you may have to move the file and vice-versa. So, we’ve implemented a Move Package refactoring tool.

This can be invoked in one of three ways:
-  a context menu on the file node in the Solution Explorer
-  drag and drop of one or more files from one directory in the Solution Explorer to another directory
-  a Smart Tag generated by editing the package name in the text editor.

I have to say that the last – the Smart Tag - is my favourite; I always try to build Smart Tags into the editor wherever I can!

So, starting off with a package name...

...and editing the package name will generate a Smart Tag marker:

Hovering over the marker and clicking displays the Smart Tag menu:

And here you can see the Preview dialog:

As usual, you can see what the refactoring will be doing (and turn off the changes if needed).

If you don’t want to edit the code, you can initiate the refactoring from the file node via a context menu:

This displays the same refactoring options as the Smart Tag.

Finally, you can drag-and-drop files (and directories) from the Solution Explorer. Again, this displays the Preview dialog for each file.

Over the next few weeks, we’ll be switching on more of the refactoring (such as Move Parameters) and doing a mini-release on a (roughly) weekly basis. The code base actually has most of the refactoring functionality in it, but we wanted to be able to manage the testing of these in a controlled fashion, since the refactoring is pretty complicated (and I write with feeling here).

Obviously, the mini-releases wont be as well tested as a full beta, but hopefully these ’edge’ releases will be quite usable.

For information on the latest ’edge’ betas, refer to the Amethyst section of the SapphireSteel forum.

Bookmark and Share   Keywords:  Amethyst  refactoring
© SapphireSteel Software 2014