views:

301

answers:

4

We've got several Flex projects, one of which has just been refactored. I'm wondering if there's an easy way to tell which classes and functions (if any) aren't being used any more?

I've discovered that we've definitely got some unused code, because running ASDoc on the entire project reports some compilation errors which don't get reported by Flex Builder (implying that those classes aren't being used any more). I'm hoping to find a more robust and complete method, and preferably one which can work at function level too.

A: 

This doesn't really answer your question but you can find the references to a single class, variable or function by selecting it (in code editor) and pushing: Ctrl+Shift+G . I think that's what you can get out of Flex / Flash Builder at the moment.

Robert Bak
I know about that. It doesn't help that some of the unused files reference each other -- they're just not referenced from the application itself.
Andrew Aylett
+2  A: 

Check out the Flex PMD tool. It was recently released in beta, but we've been using it at work for a few weeks, and it seems to work pretty nicely.

Ross Henderson
Looks good, thanks for the link :).
Andrew Aylett
@rhtx: Unfortunately, Flex PMD doesn't seem to find unreferenced code -- it only appears to have rules to find unused private functions. Unless I'm missing something?
Andrew Aylett
+2  A: 

My ugly hack:

Using the swfdump tool from SWFtools, dump the disassembly from (all of) your swf(s):

swfdump -a my.swf > dump

Get a list of all your classes:

find . -name "*.as" -exec basename {} .as \; > classes
find . -name "*.mxml" -exec basename {} .mxml \; >> classes

Apply one list to the other:

for class in $(<classes) ; do grep -q \\\<$class\\\> dump || echo $class ; done

I am doing this on Windows, using Cygwin.

Andrew Aylett
I'd never looked at SWFTools before. Wish I had... +1
Ross Henderson
A: 

Note, the swfdump tool included with the Flex SDK will work in place of the SWFTools version in the bash script listed above.

tkdave