cincheo / jsweet

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

How to make a pure js candy with a java version for testing #659

Closed evanvelikanov closed 3 years ago

evanvelikanov commented 3 years ago

I am creating Google spreadsheet macros using jsweet, that also have a pure java implementation so that I can test it locally before uploading on google script. Obviously it requires interacting with Google spreadsheet api, Logger etc. Taking Logger and Range as example, how should i define this candy for this to work both in the js and java world?

For it to work with JS side, defined as

public abstract class Logger {
    public static native void log(Object tp);
}

For Java defined as

public class Logger {
    public static void log(Object tp){
        System.out.println(tp);       
    }
}

Similarly defined Range as

package com.google_appscript; // or package def.google_appscript;
import java.util.List;
public abstract class Range {
    public native List<List<Object>> getValues();
}

Right now I am trying to have 2 maven projects to achieve it, but I have messed up some where that I am getting the error. If I define this in a com package I get the following error

TRANSPILATION ERRORS SUMMARY:
* Range.java(25,5)method 'getValues' cannot be native
* Spreadsheet.java(25,5)method 'getRange' cannot be native
* SpreadsheetApp.java(25,5)method 'getActive' cannot be native

If I define this in a def package I get the following error

* Range.java(24,1)[ts] Duplicate identifier 'Range'.
* ~\.jsweet.v3-node_modules\node_modules\typescript\lib\lib.dom.d.ts(12629,11)[ts] Duplicate identifier 'Range'.
* ~\.jsweet.v3-node_modules\node_modules\typescript\lib\lib.dom.d.ts(12669,13)[ts] Duplicate identifier 'Range'.

While I am trying to fix it at my end, I am posting this question to know the standard way of doing this. Thank You.

evanvelikanov commented 3 years ago

I was able to solve it with nothing extra. I don't know which part of the configuration was wrong, but I got it working. Those interested can check the repositories :

https://github.com/xyz-jphil/xyz-jphil-google_appscript-logger https://github.com/xyz-jphil/xyz-jphil-google_appscript-spreadsheet

lgrignon commented 3 years ago

Oh, good. Sorry I didn't help more. Duplicate identifier can occur when root package items clash with global def, but I don't know if it was this here. I am glad it's fixed anyway :)

evanvelikanov commented 3 years ago

Oh, good. Sorry I didn't help more. Duplicate identifier can occur when root package items clash with global def, but I don't know if it was this here. I am glad it's fixed anyway :)

Yes I am just committing the code, so that others with similar issues can be helped. I also don't know why the identifier was conflicting, I did several things and it finally worked. I think a mvn clean jsweet:clean was a part of what worked.

Thank you for your help, what you guided in the previous issue was sufficient to solve this problem also.

lgrignon commented 3 years ago

Yes, always clean before installing / deploying, to avoid fossilized ts/js files :)

Thanks for your reply, see you later.