Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Generate new Java code from old(Code conversion)
Generate new Java code from old [message #1734571] Thu, 09 June 2016 09:14 Go to next message
Eclipse UserFriend
I am learning xtext/Antlr. I want to transform old java code into new. This is basically to remove references to an older framework and replace them with a newer framework. What advantages do I get by using xtext and not just Antlr ? Which one should I be researching ?

Mohan
Re: Generate new Java code from old [message #1734606 is a reply to message #1734571] Thu, 09 June 2016 15:48 Go to previous messageGo to next message
Eclipse UserFriend
id use neither xtext nor antlr but e.g. something like https://github.com/javaparser/javaparser + maybe subsequent frameworks like https://github.com/ftomassetti/java-symbol-solver
Re: Generate new Java code from old [message #1734663 is a reply to message #1734606] Fri, 10 June 2016 04:36 Go to previous messageGo to next message
Eclipse UserFriend
I didn't explain it properly. So movement of code means that it is also being transformed. Some techniques involving Spring which is the new framework will be required. The transformation approaches are specific to the code. I am trying to automate it as much as possible using some transformation rules.

Mohan
Re: Generate new Java code from old [message #1734667 is a reply to message #1734663] Fri, 10 June 2016 04:39 Go to previous messageGo to next message
Eclipse UserFriend
yes but xtext will not help with the transformation,
of course you can use xtend to write the transformation.

but writing a xtext grammar for java would take LONG even if you reuse https://github.com/lorenzobettini/jbase

=> why not take a parser that already exists.
Re: Generate new Java code from old [message #1734668 is a reply to message #1734667] Fri, 10 June 2016 04:40 Go to previous messageGo to next message
Eclipse UserFriend
p.s.

maybe you can use xtext to create a "more" abstract model than pure java.
but the m2m from java to that more abstract model still needs to be done.

and then use a generator to create the java code
Re: Generate new Java code from old [message #1734745 is a reply to message #1734668] Fri, 10 June 2016 19:21 Go to previous messageGo to next message
Eclipse UserFriend
Mohan,
There's already existing Java grammar for other parser generators like antlr or javacc.
However, like Christian said, the direct way of parsing the existing code with a ready parser, then generate the code you want can be done easier without any grammar.
The only thing you need is a template engine to spit out the AST into the new format. javaparser seems to be what you want.

Another approach is to convert existing code into xml, then write an XSLT that will give you the new code. Here's some project that you can use to convert java to xml:

http://www.badros.com/greg/JavaML/ and http://www.srcml.org/doc/java_srcML.html

I haven't used either, but if I were you I would convert the existing code to XML then write an XSLT to generate the code I need.


Re: Generate new Java code from old [message #1734827 is a reply to message #1734745] Mon, 13 June 2016 06:50 Go to previous message
Eclipse UserFriend
I think I understand. The grammar isn't necessary because I am not validating anything.

I initially thought the Antlr plugin's parser tree was visually useful.

[Updated on: Mon, 13 June 2016 06:52] by Moderator

Previous Topic:Error runnig first proyect
Next Topic:How to Customize Xtext References Results View in Eclipse RCP Workbench
Goto Forum:
  


Current Time: Sun Aug 31 15:52:40 EDT 2025

Powered by FUDForum. Page generated in 0.03692 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top