Welcome to java2typescript Discussions! #1
Replies: 8 comments 5 replies
-
Hi Mike, my name is Jürgen Mutschall, located in Mannheim. I am looking for transpiling some serious packages from java to typescript, especially from the eclipse context. I tried to use java2typescript, but there are some questions:
Regards |
Beta Was this translation helpful? Give feedback.
-
About the folder layout: you are completely free to structure your application. All you need is a folder containing the JDK shims somewhere close to your application code. Once the JDK shim has reached a good state I plan to publish it on NPM and you can use it as a node module instead. But for now you need the shim sources in your app. Currently I have both repos side by side in my project folder and created a symlink in the ANTLR4 project to the java2ts lib folder. Because I designed that so that you can use Java like qualifiers, all you have to do is to import About inconsistencies let's talk in your new issue you have opened. |
Beta Was this translation helpful? Give feedback.
-
I tried to transpile https://hamcrest.org/JavaHamcrest/, only the core part, version 1.3, as a base for the junit4 library. I understand, that the java2typescript transpiler is in a very early stage, but maybe my findings may help.
IMHO the most important issues are a consistent wrapper model for java constructs that cannot be transpiled 1:1 to typescript, e.g. Iterator and Iteratable, maybe an additional class layer would help in some areas. The transpiler is not mature enough to open issues for every topic. |
Beta Was this translation helpful? Give feedback.
-
I think I should also make this more explicit: the goal for this tool is not to create a Java runtime in Typescript, that's just a side task. The main goal is to convert Java code to running TS code (provided the necessary runtime exists, be it the shims I wrote or any other port/wrapper). |
Beta Was this translation helpful? Give feedback.
-
I used the src lib from junit4: Same for an working TS runtime. Did you think about using the Google JRE emulation or the J4TS fork of it as a starting point? Every kind of shim, runtime lib, emulation, ... follow a strict "mapping model" for src-->target language. |
Beta Was this translation helpful? Give feedback.
-
The GWT JRE emulation doc is here:
https://www.gwtproject.org/doc/latest/RefJreEmulation.html
Especially the java.lang.* should be quite interesting for your approach. A
good implementation of Object, String, StringBuffer, Char, …
The most recent implemention is in
https://github.com/google/j2cl
But everything is build with j2cl/gwt in mind, so you have to add a
callable API, described here:
https://github.com/google/j2cl/blob/master/docs/jsinterop-by-example.md#calling-java-from-javascript
I think the hard work for emulation of std functionality, value types is
done and well tested (Good unit tests are included!)
Using the jre lib to bootstrap a full-functional java “user code”
transpiler to Typescript becomes quite feasible.
I would like to see a java to typescript transpiler that uses the google
j2cl/jre to leverages the blackbox approach to a more whitebox approach you
are reaching for.
What do you think?
*Von:* Mike Lischke ***@***.***
*Gesendet:* Donnerstag, 20. Oktober 2022 19:17
*An:* mike-lischke/java2typescript
*Cc:* JuergenMutschall; Comment
*Betreff:* Re: [mike-lischke/java2typescript] Welcome to java2typescript
Discussions! (Discussion #1)
Same for an working TS runtime. Did you think about using the Google JRE
emulation or the J4TS fork of it as a starting point?
Damn, I looked up and down the net to find something that would spare me
the work of writing the converter and could not find any. Thanks for these
pointers.
I played a bit with the JRE emulation and j4ts. Ran the hello world app
etc. But I can for the live of me not get enough information from the
documentation to decide if that is something useful for my situation, even
though it sounds like it would. The module j4ts was better to understand
and I could inspect the code. Unfortunately, it does not include many
things like file system emulators. I know, it's for web browsers, but for
my use case it's essential to have that. Additionally, probably due to the
way it was created (via JSweet), it looks very inefficient (Char arrays are
represented as string arrays, surrogates are not properly handled, byte
arrays use number[] instead of native JS arrays etc.).
So I guess, even though all of that is pretty exciting, I'll continue with
my approach.
Every kind of shim, runtime lib, emulation, ... follow a strict "mapping
model" for src-->target language.
Where do you see such a "model" for the Google emulator or j4ts? They have
only minimal docs about compatibility.
Your "feature" doc is a good starting point for such a model, but a more
strict "mapping" would help. E.g. how are value types handled? A "Long" is
transpiled as a class, but I found no shim. E.g the "CodePoint as a Number"
is a nice idea from a performance perspective, but fails to provide the
needed character operations. Currently a manual mapping from char to number
functionality and vice versa is needed, a Typescript class with static
methods/functions would not be very heavy to handle this. A more general
description/definition of your "type boxing/mapping" approach would be
great.
Thanks for the suggestions! Keep in mind I write the Java shims only when I
need them. So far I had not yet seen a use case for that in the code I'm
converting. My hope is that other people start using the converter and add
shims as they need them. Likely for standard types there will be shims
sooner or later, however.
Types which have no expression in TS (like char) cannot be used as is, for
obvious reasons. Wrappers for Char, Long, etc. can be written, no doubt.
Someone just needs to find time and interest to do so. I'm also currently
rethinking my decision to use native Object/object and String/string TS
types. At least for the classes we can provide shims, which also would then
be able to provide the necessary APIs (including basic hashCode and equals
support).
Autoboxing besides what TS does already will not be available, and
determining the resulting type of an expression just from parsing it is a
pretty difficult task, so the user has to add explicit boxing manually.
—
Reply to this email directly, view it on GitHub
<#1 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI3XVIGATSIYFWL5EQ2BTYLWEF5BXANCNFSM6AAAAAARAJK754>
.
You are receiving this because you commented.Message ID:
***@***.***
… |
Beta Was this translation helpful? Give feedback.
-
Hi Mike,
some years ago, I developed software using GWT. Google moved on to j2cl and
angular and a community process took over to improve GWT from v1 over v2 to
currently nearly finished GWT3.
I am waiting now for 3-4 years for the j2cl community is releasing a gwt
v1.0 based on j2cl.
To answer your questions I will try the current working status and will
give you an update about the results in the next days.
Regards
Jürgen
P.S: I you like to exchange messages in “Deutsch” please send an direct
mail email to ***@***.***
*Von:* Mike Lischke ***@***.***
*Gesendet:* Freitag, 21. Oktober 2022 00:06
*An:* mike-lischke/java2typescript
*Cc:* JuergenMutschall; Comment
*Betreff:* Re: [mike-lischke/java2typescript] Welcome to java2typescript
Discussions! (Discussion #1)
The GWT JRE emulation doc is here:
https://www.gwtproject.org/doc/latest/RefJreEmulation.html Especially the
java.lang.* should be quite interesting for your approach. A good
implementation of Object, String, StringBuffer, Char, … The most recent
implemention is in https://github.com/google/j2cl
Currently I still have trouble to understand how to use that. I don't see
TS code in the repository, only Java code. How can I convert all that to a
node module or at least a library of TS files? That's what I'm missing in
the documentation.
But everything is build with j2cl/gwt in mind, so you have to add a
callable API, described here:
https://github.com/google/j2cl/blob/master/docs/jsinterop-by-example.md#calling-java-from-javascript
The next thing which escapes my mind: why would I want to call a Java API?
I want to call TS APIs.
I think the hard work for emulation of std functionality, value types is
done and well tested (Good unit tests are included!) Using the jre lib to
bootstrap a full-functional java “user code” transpiler to Typescript
becomes quite feasible.
Yes, sounds good, but the learning curve seems steep and my gut feeling is
that without someone explaining all the principles you are lost. The
documentation alone is nearly useless.
I would like to see a java to typescript transpiler that uses the google
j2cl/jre to leverages the blackbox approach to a more whitebox approach you
are reaching for. What do you think?
Interesting idea, yes. Just need something to start with. The "Getting
Started" section does neither explain how to set up a a real project (that
section telling me to copy the sample project and then I'm done is a joke)
nor what's exactly required to take a Java library and convert it actually.
Shall I have the sources of the package somewhere or just the package file?
Does it need Java on the target machine? How to structure the project and
run the conversion? Nothing is really explained.
After all your TS app needs a node module or importable library. That's the
ultimate goal and hence the main question is: how to generate a node module
from a Java package? Do you know enough of GWT to answer these questions?
Thanks
—
Reply to this email directly, view it on GitHub
<#1 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI3XVIGITIFHB5YN43IPHHDWEG65PANCNFSM6AAAAAARAJK754>
.
You are receiving this because you commented.Message ID:
***@***.***
… |
Beta Was this translation helpful? Give feedback.
-
@JuergenMutschall For your information. I have now created an own repository for the JRE emulation and published the |
Beta Was this translation helpful? Give feedback.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions