jsweet icon indicating copy to clipboard operation
jsweet copied to clipboard

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

Open tonychunxizhu opened this issue 2 years ago • 4 comments

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

tonychunxizhu avatar Aug 17 '22 20:08 tonychunxizhu

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?

lgrignon avatar Aug 23 '22 17:08 lgrignon

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.

tonychunxizhu avatar Sep 02 '22 15:09 tonychunxizhu

Hello @tonysmarthome

Is it still the same error?

I understood that renaming package works.

lgrignon avatar Sep 03 '22 11:09 lgrignon

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.

tonychunxizhu avatar Sep 19 '22 21:09 tonychunxizhu