Re: check the history source code comment

"Lars Kühne" <[email protected]>
Newsgroups gmane.comp.java.audit.checkstyle.user
Message-ID <[email protected]>
On 3/19/07, caucabin caucabin wrote:
>     So the design is:
>
>     //because the antlr parser interface is java file, not the java Object
>     1.copy the java source code file to the system temp dir, and name is
> tempcomment.java
>     2.get all comments in the source code
>     3.for(int i = 0 ; size = comments.size; i < size; i ++)
>     {
>       comment = comments[i];
>
>       // Maybe this operation is a performance issue for write the file
>       uncommit it in the tempcomment.java
>
>       boolean isjavacode = using the antlr to parse tempcomment.java ;
>       if(isjavacode )
>       {
>          add it to the check log
>       }
>    }

Yes, that might work. Some points to consider:

* Have a look at the TreeWalker class from the CheckStyle sources,
that will give you some pointers how to start the java parser and
leverage the java grammar that CheckStyle already has.
* You will want to use a different starting symbol than
"compilationUnit", because you want to recognize statements (or blocks
of statements? or method/field definitions?).
* Try to avoid the temp files and find a solution that is Reader
based. You already have the complete source code in memory, and the
parser itself is based on Readers, not files.
* Work test driven. Play devil's advocate and try break your own
checker code. For example, try how your checker behaves for code that
is commented twice, has commented if-statements or is a commented
method/field definition.

Cheers,
Lars

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.