Update on the Java parser to create object model. My intention was to create a simple tool to compare the methods that changed from one release to another. This sounded a lot like Jdiff but Jdiff doesn�t compare the method implementation. I ended up modifying JavaCC to log the tokens and creating a watered-down Java object model (method and class inheritance info) and use the model to get the rest of the source code I needed (using source paths combined with info from package/import in the source files, a homegrown solution).
I made some mistakes in my decisions: 1) Should have used Javadoc�s doclet to get the model info. Problem I have is my users have 1.2 version of Javadoc and that version requires my code to build the Javadoc command (with all the parameters). Version 1.4 of Javadoc has programmatic interface so I�m thinking of trying it out in the future (combine that with JavaCC to parse the source code and get the tokens I need for method body comparison). 2) Using JJTree instead of building the actions in the grammar file would have been a better solution (eg: check for token types in the openNode/closeNode methods instead of building multiple actions in the grammar file). It�s actually not that much work to build the model using the actions in the grammar. Comments on using JavaCC: - Once I figured out the way it works using it seems pretty straightforward - The Java grammars out there work fine, just need to add some actions in the grammar to do the things I needed to do. - If you have a source file that ends with a single line comment the parser will throw a Token Manager error (Lexical error). Tried workaround in http://www2.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq.htm#tth_sEc3.12 but didn�t work. Ended up writing the source code into a temp file and appending a �/r� at the end of the file, not the best solution but solves the problem for now. Let me know if you have any questions. --- Roger Glover <[EMAIL PROTECTED]> wrote: > The only technology designed for Java > programmers that I have seen that will allow > you to introspect method bodies in source code > is JavaCC with a Java language grammar. But as > you noted earlier you have to write a great > deal of the code yourself. > > In any case, Ken, please keep us all posted. I > would love to find out what finally works for > you. ===== Ken Lai ***** End of Message ****** __________________________________________________ Do you Yahoo!? Y! Web Hosting - Let the expert host your web site http://webhosting.yahoo.com/ ____________________________________________________ To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm Be respectful! Clean up your posts before replying ____________________________________________________
