Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools for converting non-Java into Java source [closed]

Are there any good tools out there for automatically converting non-Java source code into Java source?

I'm not expecting something perfect, just to get the worst of the grunt work out of the way.

I guess there is a sliding scale of difficulty. C# should be relatively easy (so long as you ignore all the libraries). (well written) C++ not so bad. C requires making a little OO. (Statically type) functional languages may be easy to grok. Dynamic OO languages may require non-local analysis.

like image 910
Tom Hawtin - tackline Avatar asked Sep 05 '08 19:09

Tom Hawtin - tackline


4 Answers

One thing you can try is find a Java bytecode compiler for the language you're talking about (there are JVM compilers for all kinds of languages) and then decompile the bytecode back into Java using a decompiler like Jad.

This is fraught with peril. The regenerated code will suck and will probably be unreadable.

like image 147
jodonnell Avatar answered Sep 28 '22 03:09

jodonnell


Source-to-source migrations fall under the umbrella of Program Transformation. Program-Transformation.org tracks a bunch of tools that are useful for language recognition, analysis, and transformation. Here are few that are capable of source-to-source migrations:

  • ASF+SDF Meta-Environment - As noted, there is no new development on this tool. Instead, the developers are focusing on Rascal.
  • Rascal Meta Programming Language
  • Stratego /XT
  • TXL
  • DMS® Software Reengineering Toolkit (commercial)

If you spend any time with one of the open source tools, you'll notice that even though they include source-to-source migration as a feature, it's hard to find working examples. I imagine this is because there's no such thing as a one-size-fits-all migration. Each project/team makes unique use of a language and can vary by libraries used, type complexity, idioms, style, etc. It makes sense to define some transformations per migration. This means a project must reach some critical mass before automatic migration is worth the effort.

A few related documents:

  • An introduction to Rascal - includes a migration between the toy language Pico and Assembly starting at page 94.
  • Cracking the 500 Language Problem
  • An Experiment in Automatic Conversion of Legacy Java Programs to C# (gated) - uses TXL
like image 23
Corbin March Avatar answered Sep 28 '22 03:09

Corbin March


Google: ANTLR

like image 23
Ande Turner Avatar answered Sep 28 '22 02:09

Ande Turner


The language conversion is fairly simple, but you will find the libraries are different. This is likely to be most of your work.

like image 34
Peter Lawrey Avatar answered Sep 28 '22 01:09

Peter Lawrey