tags:

views:

807

answers:

7

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.

+1  A: 

Here's a tool for converting C# to Java.

For any language that doesn't have nearly identical language features this would be non-trivial. Core language code would be fairly straight forward to convert between languages, but what about all of the references to libraries you'd find in real production code?

Bill the Lizard
+3  A: 

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
+3  A: 

Google: ANTLR

_ande_turner_
Good point, but depending on the source-language it will be a huge thing to do.
A: 

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

Tim Williscroft
how about the reverse? I'm a java guy wanting to learn ADA
WolfmanDragon
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
A: 

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
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
A: 

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
A: 

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 wont be worth as it wont exist , its not just syntax translation from one lang to another .

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

sashank