Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 13:14 Go to next message
Mohan Radhakrishnan is currently offline Mohan RadhakrishnanFriend
Messages: 3
Registered: July 2009
Junior Member
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 19:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13186
Registered: July 2009
Senior Member
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

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generate new Java code from old [message #1734663 is a reply to message #1734606] Fri, 10 June 2016 08:36 Go to previous messageGo to next message
Mohan Radhakrishnan is currently offline Mohan RadhakrishnanFriend
Messages: 3
Registered: July 2009
Junior Member
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 08:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13186
Registered: July 2009
Senior Member
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.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generate new Java code from old [message #1734668 is a reply to message #1734667] Fri, 10 June 2016 08:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13186
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generate new Java code from old [message #1734745 is a reply to message #1734668] Fri, 10 June 2016 23:21 Go to previous messageGo to next message
Mansour Al is currently offline Mansour AlFriend
Messages: 44
Registered: June 2016
Member
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 10:50 Go to previous message
Mohan Radhakrishnan is currently offline Mohan RadhakrishnanFriend
Messages: 3
Registered: July 2009
Junior Member
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 10:52]

Report message to a moderator

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


Current Time: Wed Nov 13 09:33:42 GMT 2019

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

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

Back to the top