Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tonychunxizhu opened this issue Aug 17, 2022 · 4 comments
Open

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

tonychunxizhu opened this issue Aug 17, 2022 · 4 comments

Comments

@tonychunxizhu
Copy link

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
Copy link
Collaborator

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 lgrignon changed the title Methods name lost in generated bundle ts file when creating a java candy Creating a class in java.util.function : methods name lost Aug 23, 2022
@tonychunxizhu
Copy link
Author

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
Copy link
Collaborator

lgrignon commented Sep 3, 2022

Hello @tonysmarthome

Is it still the same error?

I understood that renaming package works.

@tonychunxizhu
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants