Java to Rust Converter

Hello,
sorry, changing the title duplicates the post and I could not figure out, how to delete it. There is nothing new here:
Please look into java-to-rust-converter-for-tedious-editing-tasks

I am a former C++ now Java-Programmer, quite new in Rust and am fascinated about the safety features of this language. So I thought, why not try to port some functionality implemented in Java to Rust.
I started with the math3 artefact from apache.

There are some task which are always the same, therefore I wrote a small server which is capable of parsing Java-Code and creating "rust"-code.

Use:
java to rust converter

A short meaningless code-snippet

class A {
     public A() {
       int i = 10;
       double f = 1;
       for (int i = 10; i < 100; i++) {
         f += i;
       }
   }
}

becomes:
struct A {
}

impl A {

  pub fn new() -> A {
     let i: i32 = 10;
     let mut f: f64 = 1;
     {
        let mut i: i32 = 10;
        while i < 100 {
            {
                f += i;
            }
            i += 1;
         }
     }
}

}

4 Likes

how it worked?

First:
Please look into java-to-rust-converter-for-tedious-editing-tasks for more information.
I accidentally duplicated the post by changing the title.

Second:
I do not understand correctly, did you try to paste some java-code into: converter, and pressed Convert?

The result you can see and copy from the editfield on the right.

The server/program works by using the javaparser-module on github and letting work some Iterators on top on the syntax tree.

1 Like

Is this project still alive? Maybe it makes sense to publish it on GitHub? So it might take off as c2rust.

See: converter-page. You can try it working using: jrconverter
The project was started 3 Years ago. I just revived it recently somewhat.
So if you have ideas, how to make it more usable, feel welcome to add issues.

Well, the best way to improve it - is to make a command line tool instead (or in addition) to the page. Then also integrating with refactoring scripts (basically all crates apart from the transpiler) can be helpful as well.

Basically the idea of changing the "transpiler" part in this diagram:

1 Like

Particularly with Oracle recently changing the licensing terms for Java.. it could be that some very big companies, say Google(who Oracle sued for using Java on Android.. and probably the reason for this change), could be interested in using a Java to Rust transpiler to convert their Java source code to Rust... they would also benefit from improve performance. Could be very interesting to some people.

2 Likes

Is this still maintained? I just tried the example from above, which doesn't compile (because Java supports implicit double -> int conversions, but Rust doesn't).

I think this would be very useful, if it produced better code.

4 Likes

Based on the web-application of aschoerk, I created ( a command line Java to rust converter (github.com)).

It can convert a java file or a folder that contains java classes.

Please, feel free to use it and improve it through PR.

1 Like