[metaas-dev] Changing Field names in a parsed AS3 source file
Dave N
dave at kitkat.f9.co.uk
Tue Feb 26 20:36:43 UTC 2008
Hi guys,
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? 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();
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?
Thanks - i really like the project, i think theres a lot you could do
with it - a C# or Java converter would be excellent! (well for me anyway).
Dave
More information about the metaas-dev
mailing list