[antlr-interest] Return List from Java.g file

Hiran Chaudhuri hiran.chaudhuri at web.de
Fri Jan 28 00:41:27 PST 2011

Am Freitag, den 28.01.2011, 02:08 +0100 schrieb charbel elkaed:
> I am using ANTLR to parse a Java File, then do some treatment on  the
> imports,  on some declarations and method invocation then regenerate
> an output a Java File.
> So far I can retrieve the imports but I think the declarations
> treatment will be a bit more complex. For the imports, I using a list
> in the Java.g.
> Any idea how can I do that?
> Is there any ANTLR API : Java->To->Java that I can use ?

Hi, Charbel.

1) A parser generates an AST to have the whole java code structure in

2) Some code would then modify that AST to 'rearrange' the imports -
whatever you need.

3) Finally you have to create code to serialise the AST, meaning to
generate your output java file.

ANTLR will help you in step 1. The other two are up to you.


More information about the antlr-interest mailing list