[antlr-interest] Modifying Java Source

Ismet Ozalp ozalpismet at gmail.com
Mon Aug 10 06:27:01 PDT 2009


First of all thank you all for your fast comments on the subject.

Terence, after I created the tokenRewriteStream

JavaLexer javaLexer = new JavaLexer(new ANTLRFileStream(file));
TokenRewriteStream tokenRewriteStream = new TokenRewriteStream(javaLexer);

Are you suggesting me to find tokens between {} and replace them with the
tokens I want?
In that case how can I detect class definition and inner class definitions
because i don't want to replace them. Maybe I am not completely
understanding
your suggestion. I feel like telling the grammar skip method definitions but
yet i am not successful.  I am using antlr 3.1.3. Also TokenRewriteStream's
delete(int from, int to) seems not deleting the tokens in it's token list? I
am just calling tokenRewriteStream.delete(10,20) and the tokens are still
there? Thank you very much...

Regards,
Ismet


On Mon, Aug 10, 2009 at 8:31 AM, Terence Parr <parrt at cs.usfca.edu> wrote:

> Hiya. Use the tokenrewrite stream and Java.g combo. add actions to replace
> between { } with new action. :)Ter
> On Aug 9, 2009, at 6:18 PM, Ismet Ozalp wrote:
>
> Hello everybody,
>
> I am a newbie; I am trying to modify java sources. What I am trying to do
> is
>
> clear the codes in the methods and change them with one line of code
>
> example method
>
>     public void delete(T t) {
>         PersistenceManager pm = PMF.get().getPersistenceManager();
>
>         try {
>             pm.deletePersistent(t);
>
>         } finally {
>             pm.close();
>         }
>
>     }
>
> changed method
>
>   public void delete(T t) {
>     throw new UnsupportedOperationException();
>   }
>
> So i need to modify the grammar some how to do this for methods in the
> source file
> currently I am trying to do something with
> http://www.antlr.org/grammar/1152141644268/Java.g
> which is written by Terence Parr. But I am a little bit lost, if anybody
> can point me to the right direction
> where I can find more information or examples about how to achieve this, it
> would be great....
>
> Thank you very much
> Ismet
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090810/adcd5085/attachment.html 


More information about the antlr-interest mailing list