jsweet icon indicating copy to clipboard operation
jsweet copied to clipboard

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

Open lalalic opened this issue 2 years ago • 2 comments

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 avatar Oct 28 '21 02:10 lalalic

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?

lalalic avatar Oct 28 '21 02:10 lalalic

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

lgrignon avatar Nov 02 '21 15:11 lgrignon