6

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.

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305

7 Answers7

5

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:

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:

Corbin March
  • 25,526
  • 6
  • 73
  • 100
5

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.

jodonnell
  • 49,859
  • 10
  • 62
  • 67
3

Google: ANTLR

Ande Turner
  • 7,096
  • 19
  • 80
  • 107
1

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

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

Any of those tools might help only if your non java code is not huge enough.

If its huge non java code and if you want to seriously translate it to java, then few things need to be thought of, its not just hundreds of lines of code, there is a design beneath it, there are few decisions taken by people beneath the code due to which certain problems might have been solved and few things have been working there. and investing time on any good translator won't be worth as it won't exist, it's not just syntax translation from one language to another.

If its not so huge code, its better to re write in java, as it has so many APIs packages out of box, it might not be big deal, hiring few interns for this also might help.

lmcanavals
  • 2,339
  • 1
  • 24
  • 35
sashank
  • 1,531
  • 2
  • 13
  • 26
0

If you just want to use some legacy C/Pascal code, you could also use JNI to call it from Java.

If you want to run it in a Java applet or similar constrained environment, and it does not have to be very efficient, you can use NestedVM (which is a MIPS to Java bytecode converter) in conjunction with a gcc cross-compiler that compiles to MIPS). But don't expect to get readably Java code from that.

mihi
  • 6,507
  • 1
  • 38
  • 48
  • The NestedVM toolchain is rather heavy and a bit outdated. Bascially you convert MIPS instructions to Java Byte Code (MIPS32 was chosen for being the closest to the JVM ) – Thorbjørn Ravn Andersen Oct 25 '09 at 16:04
-1

ADA to Java can be done with a find-and-replace!

Tim Williscroft
  • 3,705
  • 24
  • 37
  • how about the reverse? I'm a java guy wanting to learn ADA – WolfmanDragon Dec 12 '08 at 18:45
  • ADA is not too different, templates are every similar, packages are like java static classes, ADA classes are like Java ones. Standard IO is generic in ADA>. Only weird thing is package extension, and that files trees and package names don't line up 1:1 like they do in Java. So like C++ :) – Tim Williscroft Jan 12 '09 at 06:16