cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 159 forks source link

question: how to use module transpile, so classes in java.lang, and java.util can be linked correctly. #712

Open lalalic opened 2 years ago

lalalic commented 2 years ago
package com.a;
import java.util.Collections;
public class Util{
   public static int test(){
        Collections.unmodifiableMap(null);
        System.arraycopy(null,0,null,0,0);
        return 1;
    }
}

transpiled as following:

export class Util {
    public static test(): number {
        Collections.unmodifiableMap<any, any>(null);
        System.arraycopy(null, 0, null, 0, 0);
        return 1;
    }
}
Util["__class"] = "com.a.Util";

js as following:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* Generated from Java with JSweet 3.2.0-SNAPSHOT - http://www.jsweet.org */
class Util {
    static test() {
        Collections.unmodifiableMap(null);
        System.arraycopy(null, 0, null, 0, 0);
        return 1;
    }
}
exports.Util = Util;
Util["__class"] = "com.a.Util";

j4ts has been added as candy.

So the problem is how and where to configure to make the js Util work with Collections, and System at runtime, which is actually at java.util.Collections, and java.lang.System in j4ts.js.

lalalic commented 2 years ago

should jsweet use full qualified name for Collections and System even when module transpiling?

or add such import

import Collections=java.util.Collections
import System=java.lang.System

how can I change the source code to get this expected TS?

lgrignon commented 2 years ago

Did you take a look at the module options in https://github.com/lgrignon/jsweet-maven-plugin README?

Some examples are available on the JSweet website as well