Recently I have been creating a lot more libraries for the flash player that rely on reflection, dawn being one of those. I found that my reflection requirements where not easily met with the current tools, and so, Fussy was born!
Love it or hate it describeType is the only (almost) way to preform reflection on types in actionscript, it returns a XML document containing information about a type in one big dump! There are a number of excellent and proven libraries out their that can convert that XML dump into a nice OO data structure for you to code against, and it crossed my mind several times while developing dawn that they could make my life a lot easier. I however, created another reflection library... what was I thinking!?
Thing is, I have never needed a full strongly typed objected orientated representation of my type! That would be nice of course, but when I turn to reflection its not to create Method and Parameter objects (I'd rather the runtime did that to be honest) its because there are specific things about a type that I need to find.
A simple example of what I need reflection for in dawn would be to find all the methods in a type that have been decorated with the [Inject] metadata and have one or more arguments. i.e. all the injectable methods for a Class. Whether the reflection API gives me a XML document or the same information parsed into types I'm still going to have develop a way of finding all the methods with Inject metadata. Maybe that will be with e4x or maybe a loop over some objects (perhaps ensuring that they are methods not variables/accessors), then I will need to check that those methods have some arguments and are thus injectable. So whatever the means the types reflection information is provided by, the actual logic of my task is entirely up to me to develop and test.
With all that in mind, I built Fussy to be a little different from current reflection libraries (at least those that I know of). I wanted something to help me query my types, where the query represented whatever I wanted to find out about my types. To show you what I mean by "query", lets see how fussy allows me to find the injectable methods on a type (the problem from above)
Start by creating a fussy
Now to describe my query
Now I can execute that query against any type, and get a array of strongly types Method objects
And TA DA! I have strongly typed method objects that satisfy my query for MyClass.
var fussy:Fussy = new Fussy()
var query:IQuery = fussy.query().findMethods().withMetadata("Inject").withArguments();var methods:Array = query.forType(MyClass);