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

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

<p>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.</p>

[{'answer_id': 46790, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 3, 'selected': False, 'text': "<p>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.  </p>\n\n<p>This is fraught with peril.  The regenerated code will suck and will probably be unreadable.</p>\n"}, {'answer_id': 48609, 'author': 'Ande Turner', 'author_id': 4857, 'author_profile': 'https://Stackoverflow.com/users/4857', 'pm_score': 2, 'selected': False, 'text': '<p>Google: ANTLR</p>\n'}, {'answer_id': 48898, 'author': 'Tim Williscroft', 'author_id': 2789, 'author_profile': 'https://Stackoverflow.com/users/2789', 'pm_score': -1, 'selected': False, 'text': '<p>ADA to Java can be done with a find-and-replace!</p>\n'}, {'answer_id': 790624, 'author': 'mihi', 'author_id': 90203, 'author_profile': 'https://Stackoverflow.com/users/90203', 'pm_score': 0, 'selected': False, 'text': '<p>If you just want to use some legacy C/Pascal code, you could also use JNI to call it from Java. </p>\n\n<p>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 <a href="http://nestedvm.ibex.org/" rel="nofollow noreferrer">NestedVM</a> (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.</p>\n'}, {'answer_id': 790659, 'author': 'Peter Lawrey', 'author_id': 57695, 'author_profile': 'https://Stackoverflow.com/users/57695', 'pm_score': 1, 'selected': False, 'text': '<p>The language conversion is fairly simple, but you will find the libraries are different.\nThis is likely to be most of your work.</p>\n'}, {'answer_id': 1879119, 'author': 'sashank', 'author_id': 223818, 'author_profile': 'https://Stackoverflow.com/users/223818', 'pm_score': 0, 'selected': False, 'text': "<p>Any of those tools might help only if your non java code is not huge enough. </p>\n\n<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 4381267, 'author': 'Corbin March', 'author_id': 7625, 'author_profile': 'https://Stackoverflow.com/users/7625', 'pm_score': 3, 'selected': False, 'text': '<p>Source-to-source migrations fall under the umbrella of <a href="http://www.program-transformation.org/Transform/ProgramTransformation" rel="noreferrer">Program Transformation</a>. Program-Transformation.org tracks a <a href="http://www.program-transformation.org/Transform/TransformationSystems" rel="noreferrer">bunch of tools</a> that are useful for language recognition, analysis, and transformation. Here are few that are capable of source-to-source migrations:</p>\n\n<ul>\n<li><a href="http://www.meta-environment.org/" rel="noreferrer">ASF+SDF Meta-Environment</a> - As noted, there is no new development on this tool. Instead, the developers are focusing on Rascal.</li>\n<li><a href="http://www.rascal-mpl.org/" rel="noreferrer">Rascal Meta Programming Language</a></li>\n<li><a href="http://strategoxt.org/" rel="noreferrer">Stratego /XT</a></li>\n<li><a href="http://www.txl.ca/nabouttxl.html" rel="noreferrer">TXL</a></li>\n<li><a href="http://www.semdesigns.com/Products/DMS/DMSToolkit.html" rel="noreferrer">DMS&reg; Software Reengineering Toolkit</a> (commercial)</li>\n</ul>\n\n<p>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.</p>\n\n<p>A few related documents:</p>\n\n<ul>\n<li><a href="http://www.rascal-mpl.org/pub/Rascal/Documentation/rascal-slides.pdf" rel="noreferrer">An introduction to Rascal</a> - includes a migration between the toy language Pico and Assembly starting at page 94.</li>\n<li><a href="http://www.cs.vu.nl/~x/500/500.html" rel="noreferrer">Cracking the 500 Language Problem</a></li>\n<li><a href="http://academic.research.microsoft.com/Paper/2700041.aspx" rel="noreferrer">An Experiment in Automatic Conversion of Legacy Java Programs to C#</a> (gated) - uses TXL</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/46758', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4725/']