• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Java source parsing/generation libraries

Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Java Cowboy
Posts: 16084
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic