File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java source parsing/generation libraries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java source parsing/generation libraries" Watch "Java source parsing/generation libraries" New topic
Author

Java source parsing/generation libraries

Marcin Moscicki
Greenhorn

Joined: Aug 12, 2005
Posts: 6
I am writing a tool, which output is a set of java source classes (*.java files). Although I got a first version working, I found that code generation is not a piece of cake - especially if you allow to specify snippets to include in the input and have to assert everything will compile, and, ideally, print it according to a given source formatting policy. This calls for a full syntactic tree.

Do you now any libraries that would provide some or all of the following:
- java code model classes for syntactic tree, like Clazz, Instruction, For, Declaration, Variable, etc;
- methods for printing a given tree as source code to a stream;
- methods for parsing streams and building that model tree ?

Every IDE has to have implementations of the following, including open-source Eclipse, so I am half expecting it is already done and I could just use it after a resonable learning time.

Any experiences or ideas for futher investigation path?

Thanks,


1,000,000 lemmings can't be wrong!<br />mmoscicki@justimagine.pl
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

Eclipse indeed has this, ofcourse, in the JDT Core project.

JDT Core is the Java infrastructure of the Java IDE. It includes:

...

A Java Model that provides API for navigating the Java element tree. The Java element tree defines a Java centric view of a project. It surfaces elements like package fragments, compilation units, binary classes, types, methods, fields.


Maybe it's worth to take a closer look if this is something you really need to do.

You could also have a look at JavaCC, a Java parser generator. It includes a Java grammar as one of the examples (but only for Java 1.0 and 1.1...).

If you search a little with Google, you'll find some other things like this one: JParse (I have no idea how useful or complete this is).
[ August 02, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java source parsing/generation libraries
 
Similar Threads
IElementChangedListener
Java Problem
Error during EJB Deploy in RAD
How get method source code from a class
Get the list of packages, classes in packages and methods in class