[metaas-dev] Changing Field names in a parsed AS3 source file

Dave Newton dave at kitkat.f9.co.uk
Sat Mar 15 16:35:26 UTC 2008


David Holroyd wrote:
> On Sat, Mar 15, 2008 at 01:04:03PM +0000, Dave Newton wrote:
>   
>> I figured out what the xml's were for the other day and it compiled 
>> fine, and worked correctly so the cvs version is fixed :). I may have to 
>> go higher up in metaas to achive what i want though - here's an example
>>
>>  lets say I have a class like this
>>
>> public var CTile {
>>     public var tile1:Tile1;
>>     public var tile11:Tile11;
>>     public function DrawTile1(tile1:Tile1):void {
>>         public var tile1Name:String = tile1.name;
>>         trace("Drawn Tile1");
>>     }
>>     public function DrawTile11(tile11:Tile11):void {
>>         public var tile11Name:String = tile11.name;
>>         trace("Drawn Tile11");
>>     }
>> }
>>
>> and i want to change "Tile1" to "WallTile" then i can't easily search 
>> replace, but if i could access through a tokenized version like the 
>> following
>>
>> public var $0 {
>>     public var $1:$2;
>>     public var $3:$4;
>>     public function $5($6:$2):void {
>>         public var $7:String = $6.$8;
>>         trace("Drawn Tile1");
>>     }
>>     public function $9($10:$4):void {
>>         public var $11:String = $10.$12;
>>         trace("Drawn Tile11");
>>     }
>> }
>>
>> then i could just replace all $2 tokens with "WallTile" in the generated 
>> ouput. How hard do you think it would be to add the functionality to 
>> metaas to change all the occurances of a token (variable, field, method, 
>> class) in a project (multiple source files)? Or maybe theres an 
>> alternative like just getting a list of places where the token is used, 
>> or just a list of tokens and then i could walk through and modify the 
>> script as necessary? I can't really see anything similar in the api - 
>> and i've not delved deeper into metaas yet.
>>     
>
> I am going to add an implementation of the visitor/iterator pattern that
> will make it easier to do stuff like this.  You can of course do this by
> hand (look at evey method / check method's return type / replace return
> type if required), but really metaas should be providing more help in
> this common scenario.
>
> It's worth noting that metaas is only exposing syntax at the moment --
> it doesn't do any semantic analysis.  This means that, for instance, if
> you had two classes called 'Tile1' that were in different packages,
> metaas currently doesn't do anything to help you work out which one
> you've actually got at a particular point in the code.  One day, it
> would be nice to have that kind of stuff in metaas, but I don't think it
> even handles all of the details of AS3 syntax yet, so the complicated
> stuff will have to wait :)
>
>
> ta,
> dave
>
>   

That'd be really useful - if theres anything i can do to help with 
implementing that i'd give it a go - it's probably a bit over my head at 
the moment, but maybe theres some grunt work i can do when you start 
looking at that functionality. I'd rather spend longer adding to metaas 
for everyones benefit that writing a temporary cludgy hack that would be 
redundant when you implement that common functionality. As for the class 
problems, i think i could probably watch out for those (and just report 
it for manual checking/changing), theres also some gotchas with untyped 
objects being anything, and also getDefinitionByName. I think your right 
that getting AS3 parsing right is more important than the more 
complicated functionality, as they wouldn't be much use if you couldn't 
throw any as3 code at it.

Just being cheeky but how far down the todo list would this come? And 
any tips where to start looking in the metaas code to try and grasp how 
that'd work so i can atleast be looking to help out in the future!

Thanks again :)

Dave

*Sorry bout the double post - for some unknown reason my thunderbird 
sends it to your address if i use reply, and if i use reply all it just 
sends it to the list - strange!




More information about the metaas-dev mailing list