[antlr-interest] Modifying Java Source
Terence Parr
parrt at cs.usfca.edu
Wed Aug 12 11:06:25 PDT 2009
hooray! how about adding a FAQ entry to the wiki? :)
Ter
On Aug 12, 2009, at 9:16 AM, Ismet Ozalp wrote:
> Thank you very much Terence I got everything working fine right now.
>
> On Mon, Aug 10, 2009 at 11:39 PM, Terence Parr <parrt at cs.usfca.edu>
> wrote:
> do a replace not insert. get token index from '{' and '}'. label
> those tokens.
> Ter
>
> On Aug 10, 2009, at 12:38 PM, Ismet Ozalp wrote:
>
> Thanks again Terence.
>
> Ok I believe now I getting at least something correct
>
> i replaced the
> methodBody
> : block
> ;
>
> With this
>
> methodBody
> : {
> TokenRewriteStream input2 = (TokenRewriteStream) input;
> input2.insertAfter(input.index(),"throw new
> UnsupportedOperationException();");
> }
> ;
>
> and now i have throw new UnsupportedOperationException(); in methods
> but how do i delete the existing codes in the methodBody?
>
> you said ask for { } how do i do that ? how can I find indexes of
> { } in methodBody if I can find the index of them I can use replace
> method and everything will be good.
>
> Regards,
> Ismet
>
>
> On Mon, Aug 10, 2009 at 8:01 PM, Terence Parr <parrt at cs.usfca.edu>
> wrote:
> go to method definition in grammar. ask for tokens { and }. context
> is your key not simply scanning for tokens.
> T
>
> On Aug 10, 2009, at 6:27 AM, Ismet Ozalp wrote:
>
> 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/20090812/26ad8e21/attachment.html
More information about the antlr-interest
mailing list