as3parser-framework :: lazy as3 code creation
Hi,
I just thought I would run this past all the people that got scared at the last post knowing you can now create actionscript3 code with actionscript3 code.
Now you can create actionscript3 code with a String of actionscript3 code, then print out the actionscript3 code again.
Lets see, how many times did I say actionscript3, 6, OK that’s good.
Git Hub source code:
Input:
var code:String = "package my.domain {" + "public class UnitTest {" + "protected const MY_CONSTANT:int = 42;" + "[Test]public function testMethod1():void{}" + "[Test]public function testMethod2():void{}" + "[Test]public function testMethod3():void{}" + "}}" var file:AS3SourceFile = new AS3SourceFile(null, new SourceCode(code, "", "")); file.buildAst(); var typeNode:ITypeNode = file.compilationNode.typeNode; var method:IMethodNode = typeNode.getMethod("testMethod2"); method.description = "See, this editing a string with code is fun!"; method.newDocTag("author", "Yeah me"); var meta:IMetaDataNode = method.getMetaData("Test"); meta.description = "Just in case you didn't know, I unit test."; typeNode.removeMethod(typeNode.getMethod("testMethod1")); typeNode.newMetaData("TestSuite"); typeNode.description = "Class documentation is good also, but I am lazy!" var result:String = BuilderFactory.instance.buildFile(file);
Output:
package my.domain { [TestSuite] /** * Class documentation is good also, but I am lazy! */ public class UnitTest { protected const MY_CONSTANT:int = 42; /** * Just in case you didn't know, I unit test. */ [Test] /** * See, this editing a string with code is fun! * * @author Yeah me */ public function testMethod2():void { } [Test] public function testMethod3():void { } } }
Notice this uses the parser and builder!
Mike
Recent Comments