From Alberto.Acevedo at us.Army.Mil Wed Apr 9 14:52:53 2008
From: Alberto.Acevedo at us.Army.Mil (Acevedo, Alberto Mr CIV USA AMC)
Date: Wed, 9 Apr 2008 10:52:53 -0400
Subject: [metaas-dev] Some code to contribute - Actionscript comment header
generator
Message-ID: <95EA9EACA466CF40AD26E3CD8987925901343964@MONMBE010C85207.nae.ds.army.mil>
I implemented this Java utility to autogenerate comment headers for
actionscript source code. You specify the root path of your Flex project
and the utility will add comment headers to all the files (class, and
functions) found in the project. The utility by default do not overwrite
existing comments. By using the MetaAS ActonScript code generator it
made the implementation of this utility very easy. You can modify the
format of the comment headers based on your own requirements. I hope you
find this utility useful.
I found a problem with MettaAS and the super keyword. Hopefully this bug
will get fix in the next release of MetaAS.
Thanks for the great work on the MetaAS ActonScript code generator.
Alberto Acevedo
Computer Engineer
US Army CERDEC SED/ABSD
Fort Monmouth , New Jersey
package ascommentgenerator;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import uk.co.badgersinfoil.metaas.ActionScriptFactory;
import uk.co.badgersinfoil.metaas.ActionScriptParser;
import uk.co.badgersinfoil.metaas.ActionScriptProject;
import uk.co.badgersinfoil.metaas.dom.ASClassType;
import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
import uk.co.badgersinfoil.metaas.dom.ASMethod;
import uk.co.badgersinfoil.metaas.dom.ASPackage;
import uk.co.badgersinfoil.metaas.dom.ASType;
/**
*
* @author Alberto.Acevedo
* @date 04/08/2008
* @Version 0.1
* @ revisions
* @log 04/08/2008 versionn 0.1 - when it was initially created.
*
* @description This utility add "MCS like" comment headers to
actionscript source code.
* Adding comments headers is tedious and this utility will make the
adding of comments painless
* because the developer only need to worry about adding the description
of the functions and parameters
* This utility is able to recursevely traverse the directory hierarchy
and add comments to all
* As files under the specified root Flex project folder or a specific
package. This utility is best used when
* implementing new AS classes. The developer write the signatures of
the functions and then use
* this utility to add all the comment headers. Be careful when setting
the forceOverwrite to true because
* it will overwrite or reset any existing comments. My advice is to
keep the default of not overwriting.
* @issues This utility is based on the metaas open source library. This
library complaints when
* it finds the super keyword. The workaround is to comment out the line
where the keyword is located
* and then run the utility.
* @usage
* 1) Open project in Netbeans
* 1) Change the root path according to your Flex project location
or package
* 2) Change the author according to the developer
* 3) to overwrite any existing comments set forceOverwrite to true.
Be careful!!
* 4) Always keep the latest AS files source code in SS. Checkout
only the files you want
* to add comment headers. If you by mistake overwrite any
existing comments the solution is
* to get the latest from SS.
* 5) run the project by clicking the Netbeans toolbar/Run/Run
main.
* 6) All AS files now have comments headers. The developer is
responsible
* for the filling out of the descriptions for each comment
header generated.
*
*/
public class Main {
// Change the root path according to your Flex project location
// rootpath can also be a spacific package.
static String rootPath = "D:/Flex/projects/checktree";
// Change the author according to the developer
static String author = "Alberto Acevedo";
// set to true to overwrite any existing comments. Default is false.
static boolean forceOverwrite = false;
static ActionScriptFactory fact = new ActionScriptFactory();
static ActionScriptProject proj = fact.newEmptyASProject(rootPath);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
File projectRootDir = new File(rootPath);
visitAllDirsAndFiles(projectRootDir);
proj.writeAll();
} catch (Exception ex) {
}
}// public static void main(String[] args)
/*
* Generates the header comment for the method.
*/
public static String generateMethodDescription(String methodName,
List paramList, String returnDescription) {
String description = "";
String parameterComment = "";
String methodParameters = "";
String parameter = null;
int len = paramList.size();
for (int index = 0; index < len; index++) {
parameter = (String) paramList.get(index).toString();
if (index == len - 1) {
methodParameters += parameter;
} else {
methodParameters += parameter + ",";
}
parameterComment += "\nadd
description\n" +
"\n";
}
description =
"Name: " + methodName + "(" + methodParameters + ")\n" +
"\n" +
"\n" +
"It performs the following steps:\n" +
"1) add step 1 if any\n" +
"2) add step 2 if any\n" +
"3) add step 3 if any\n" +
"\n" +
"\n" +
"Parameters:\n";
description += parameterComment;
description += "\n" +
"Returns:\n" +
"" + returnDescription + "\n";
return description;
}
/*
* Generates the header comment for the class.
*/
public static String generateClassDescription(String className,
String author) {
String description = "";
description =
"\n" +
"Name:" + className + "\n\n" +
"Description:\n" +
"Author:" + author + "\n" +
"Date:" + new Date().toString() + "\n" +
"Notes:\n" +
"\n";
return description;
}
/*
* Locates all the AS files under the specified root path.
*/
public static void visitAllDirsAndFiles(File dir) {
if (dir.isFile() && dir.getName().contains(".as")) {
processFile(dir);
}
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
visitAllDirsAndFiles(new File(dir, children[i]));
}
}
}
/*
// Process only directories under dir
public static void visitAllDirs(File dir) {
if (dir.isDirectory()) {
processFile(dir);
String[] children = dir.list();
for (int i=0; i
References: <95EA9EACA466CF40AD26E3CD8987925901343964@MONMBE010C85207.nae.ds.army.mil>
Message-ID: <20080409215744.GA24318@badgers-in-foil.co.uk>
Cool! Thanks for sharing your code.
I'm really glad that you found metaas useful. :)
On Wed, Apr 09, 2008 at 10:52:53AM -0400, Acevedo, Alberto Mr CIV USA AMC wrote:
> I implemented this Java utility to autogenerate comment headers for
> actionscript source code. You specify the root path of your Flex project
> and the utility will add comment headers to all the files (class, and
> functions) found in the project. The utility by default do not overwrite
> existing comments. By using the MetaAS ActonScript code generator it
> made the implementation of this utility very easy. You can modify the
> format of the comment headers based on your own requirements. I hope you
> find this utility useful.
>
> I found a problem with MettaAS and the super keyword. Hopefully this bug
> will get fix in the next release of MetaAS.
>
> Thanks for the great work on the MetaAS ActonScript code generator.
--
http://david.holroyd.me.uk/
From geekrelief at gmail.com Mon Apr 28 21:28:50 2008
From: geekrelief at gmail.com (Don-Duong Quach)
Date: Mon, 28 Apr 2008 14:28:50 -0700
Subject: [metaas-dev] Reusing the ANTLR grammar
Message-ID:
Hi,
I'm trying to build an Actionscript 3 to haxe http://haxe.org translator,
and I've been taking a closer look at metaas to see if I could reuse the AS3
and island grammars as the basis for it. I thought I might as well try to
build something robust with ANTLR than hand code a translator, but I've into
a couple snags with building the project.
I was hoping maybe David Holroyd or someone would give me some pointers on
how to alter the grammar into a tree grammar for rewriting as I'm still
learning how to use ANTLR.
Just as a side note, I setup Netbeans with a Maven plugin to build the
metaas project but ran into some dependency issues with the maven-archiver,
plexus-archiver and plexus-components. I stopped trying to resolve them at
that point because I wanted to focus on the task of the tree grammar.
I've been reading through the docs and examples, but I don't know I would
translate the certain parser rewrites into a tree grammar rule. For
example:
classDefinition[LinkedListTree annos, LinkedListTree mods]
: CLASS ident
classExtendsClause
implementsClause
typeBlock
-> ^(CLASS_DEF {$annos} {$mods} ident classExtendsClause
implementsClause typeBlock)
;
In The Definitive Guide to ANTLR, Terrence Parr says to copy the rules over
like so:
classDefinition[LinkedListTree annos, LinkedListTree mods]
: ^(CLASS_DEF {$annos} {$mods} ident classExtendsClause
implementsClause typeBlock)
;
But what would I do about the {$annos} and {$mods} elements in the rule? I
figure the parameter clause should be removed, but what should I use to
reference the annos and mods elements in the AST?
Thanks,
Don
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.badgers-in-foil.co.uk/pipermail/metaas-dev/attachments/20080428/39eaa221/attachment.htm