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

David Holroyd dave at badgers-in-foil.co.uk
Thu Mar 6 23:40:24 UTC 2008


On Tue, Feb 26, 2008 at 08:36:43PM +0000, Dave N wrote:
>  I'm new here, new to java, fairly new to AS3 and very new to metaas - 
> so be gentle! I hope it's ok to post to a dev list - but i couldn't find 
> a user one?

No worries!

> I've got to convert a lot of old code in lots of files to 
> as3, and i've been looking for a way to automate some of it, and metaas 
> looks ideal. I've been playing around with it, and tried various things 
> - i'm probably doing something really dumb! I can change the name of a 
> field, but when i try to save it, it never works. I've tried allsorts of 
> ways and still haven't found one that works - i'm not sure if it metaas, 
> java or most likely just me. Should the following work? (it writes the 
> new file out, but without the change).
> 
>         ActionScriptFactory fact = new ActionScriptFactory();
>         FileInputStream in = new FileInputStream("dungeon.as");
>         InputStreamReader reader = new InputStreamReader(in);
>         ActionScriptParser parser = fact.newParser();
>         ASCompilationUnit unit = parser.parse(reader);
>        
>         //look for variable tileColour
>         //ASPackage pkg = unit.getPackage();
>         ASClassType asclass = (ASClassType)unit.getType();
>         ASField field =  asclass.getField("tileColour1");
>         System.out.println(field.getName());
>         field.setName("wallTileColour");  
>         System.out.println(field.getName());
>        
>         //check to see if it's been updated
>         field = 
> ((ASClassType)unit.getType()).getField("wallTileColour");    
>         System.out.println(field.getName());
>        
>         //ok, now add compilation unit to current project
>         ActionScriptProject proj = fact.newEmptyASProject("."); 
>         proj.addCompilationUnit(unit);
>         proj.setOutputLocation("fixed\\");
>         proj.writeAll();

Looks like it should work, so probably metaas has a bug.

Is the input actually an AS2 file, or has it already had the basic
transformation to AS3 done?


> I also checked out the cvs version and compiled that, but just kept give 
> me a "NoViableAltException antlr" error but it's probably me done 
> something wrong - are there many important updates in the cvs?

I think it might help to see the input file that you are trying to
process.  Can you send that too?

You mentioned in another email that you've used antlrworks to compile
the grammars included in the codebase.  Did you try to use Maven to
build the project?  This is the preferred way :)


thanks!
dave

-- 
http://david.holroyd.me.uk/



More information about the metaas-dev mailing list