views:

299

answers:

4

I'm working on an app that converts source code from using one framework to another.
I really wanted to make the agonizing monotonous job automatic.
After looking a lot for something that code help me treat source code in an object-oriented way and modify it the closest thing I've found was JaxMeJS and that's short of what I need too.

I've been working at creating my own parser using antlr, but would love not having to do it by myself.

Any recommendations? Of course I'd rather a Java solution, but I have an open mind.

Thanks!

+3  A: 

I don't have any great advice for you, but I wanted to point out that there are a couple of Java 1.5 grammars for Antlr available already on their grammar list.

You might also want to take a look at the Eclipse source. They should have a very robust parser, and they already have code transformations (refactorings) built-in, so you'll have some valuable example code.

Derek Park
I've decided this is the best to go with, and used antlr. Thanks!
abyx
A: 

@Derek: Thank you. I'm already using an existing grammar, but am adapting it to extract a useful abstraction of the parts I need from the code.

The eclipse part sounds interesting, I'll give it a look.

abyx
+1  A: 

You can use eclipse jdt. Its core there is a powerful parser and compiler. I think it is hard to set up if you are not used to eclipse plugin development.

An alternative is Spoon. I use this Framework to parse and process .java files. I think it can handle the same problem domain as JaxMeJS. But it is newer and well maintained (very good mailing list!). You can either process your input files manually or develop so called Spoonlets, which gives you the power of AOP to code transformation.

Marcel
+1  A: 

What you want is a program transformation system.

The DMS Software Reengineering Toolkit is just such a system, with robust parsers (and unparsers) for Java, C#, C,C++, Python, COBOL, PHP and many more languages.

Trust me, you don't want to repeat the effort it takes just to build the robust langauge front ends, let alone the machinery underneath that makes it possible to automate the modification of code.

Ira Baxter