cincheo / jsweet

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

Creating a class in java.util.function : methods name lost #729

Open tonychunxizhu opened 1 year ago

tonychunxizhu commented 1 year ago

in a java candy, there is a file named FunctionClassTest.java

package java.util.function;
public class FunctionClassTest<T> {
    public static <T> FunctionClassTest<T> myMethod1(java.util.Comparator<? super T> comparator) {
        return null;
    }

    public static <T> FunctionClassTest<T> myMethod2(java.util.Comparator<? super T> comparator) {
        return null;
    }
}

in bundle.ts of candy, it will be

/* Generated from Java with JSweet 3.2.0 -SNAPSHOT http://www.jsweet.org */
namespace java.util.__function {
    export class FunctionClassTest<T> {
        public static <T>(comparator: any): () => T {
            return <any>(((funcInst: any) => { if (funcInst == null || typeof funcInst == 'function') { return funcInst } return () =>  (funcInst['<init>'] ? funcInst['<init>'] : funcInst) .call(funcInst)})(null));
        }

        public static <T>(comparator: any): () => T {
            return <any>(((funcInst: any) => { if (funcInst == null || typeof funcInst == 'function') { return funcInst } return () =>  (funcInst['<init>'] ? funcInst['<init>'] : funcInst) .call(funcInst)})(null));
        }
    }
    FunctionClassTest["__class"] = "java.util.function.FunctionClassTest";
}

the methods myMethod1 and myMethod2 lost. because no methods name, bundle.ts can't be compiled to javascript

lgrignon commented 1 year ago

Thanks for your bug report.

I guess this is because it is located in the special package java.util.function

Can you confirm it works if you change package?

tonychunxizhu commented 1 year ago

Thanks, @lgrignon yes, it works if I change the package name to java.util.function for this file. however, if I refactor it to java.util.function for all classes under JDK, the error still exists.

lgrignon commented 1 year ago

Hello @tonysmarthome

Is it still the same error?

I understood that renaming package works.

tonychunxizhu commented 1 year ago

Hi @lgrignon , sorry for late reply. I create a repo for it if you don't mind. https://github.com/tonysmarthome/j4ts-funtions you can see the bundle.ts file. the errors still exist. if I refactor java.util.function to java.util._function (not function), there some errors disappear, but the default method in interfaces still can't be handled. I guess it might because transpiler refactors all "funtion" to "__funtion" but ignores the package name.