as3parser-framework :: IAS3Book API access examples
Hello,
Well much progress on this end. The IAS3Book API is getting implemented. Using the as3book branch of the source code the following is code possible.
The class and interface member access is next on the list (it’s already written in java, just porting it over)
.
Note: There is no SWC for this framework yet as it is in alpha and much API is going to be added before I am finished. As some have wondered, there is going to be a write API into the AST to create .as, .mxml and asdoc comments from actionscript code.
More to come later.
public function loadBook():void { var book:IAS3Book = BookFactory.instance.createBook(); var mySourcePath:String = "C:\\dev\\workspace\\opensource\\as3parser-framework\\src"; // create a source directory var srcDir:File = new File(mySourcePath); var sources:Array = []; // get all File instances in source path recursivly var files:Array = readFiles(srcDir); for each (var file:File in files) { var sourceFile:ISourceFile = NodeFactory.instance.createSourceFile( FileUtil.readFile(file.nativePath), file.nativePath, mySourcePath); try { // build the source file's AST sourceFile.buildAst(); // add the source file to the book book.addSourceFile(sourceFile); } catch (e:Error) { trace(e.message); trace("Error parsing " + sourceFile.fileName); } } // proccess all SourceFile trees book.process(); // now you have access to all the book's accessor API // Vector.<IClassTypeNode> book.access.classTypes; // Vector.<IFunctionTypeNode> book.access.functionTypes; // Vector.<IInterfaceTypeNode> book.access.interfaceTypes; // Vector.<ISourceFileCollection> book.access.sourceFileCollections; // Vector.<ITypeNode> of class|interface|function book.access.types; // returns the IClassTypeNode or null book.access.findClassType("my.domain.Class"); // returns the IFunctionTypeNode or null book.access.findFunctionType("my.domain.globalFunction"); // returns the IInterfaceTypeNode or null book.access.findInterfaceType("my.domain.IInterface"); // returns the ITypeNode or null book.access.findType("my.domain.Class"); // Vector.<ITypeNode> book.access.getImplementedInterfaces(classAType); // Vector.<ITypeNode> book.access.getInterfaceImplementors(classAType); // Vector.<ISourceFileCollection> book.access.getSourceFileCollection("my.domain"); // Vector.<ITypeNode> book.access.getSubClasses(classAType); // Vector.<ITypeNode> book.access.getSubInterfaces(iInterfaceAType); // Vector.<ITypeNode> book.access.getSuperClasses(classAType); // Vector.<ITypeNode> book.access.getSuperInterfaces(iInterfaceAType); // returns ITypeNode book.access.getType("my.domain.Class"); // Vector.<ITypeNode> all types in package book.access.getTypes("my.domain"); // Boolean book.access.hasType("my.domain.Class"); } protected function readFiles(directory:File, result:Array = null):Array { if (result == null) result = []; var directories:Array = directory.getDirectoryListing(); for each (var file:File in directories) { if (file.isDirectory) { result = readFiles(file, result); } else if (file.extension == "as" || file.extension == "mxml") { result.push(file); } } return result; }
Mike
Recent Comments