cincheo / jsweet

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

Refelection support ? #746

Open maheshkurmi opened 1 year ago

maheshkurmi commented 1 year ago

Does jsweet support reflection? Upto what extent? Following do not work

  1. creating instance from constructor definion?
  2. Class.isInstanceOf method doesn't exist
  3. Passing String.class (or Double.class) as parameter 'Class' throws Argument of type 'StringConstructor' is not assignable to parameter of type
  4. ClassArray using Array.newInstance(itemClas, 0).getClass() throws error
lgrignon commented 1 year ago

Hello @maheshkurmi

JSweet has minimal support for reflection. It depends on whether you use J4TS or not, but you can expect basic introspection to be available (get methods of a class, get class name, get method name .. you can find detailed implementations in JSweet adapter: https://github.com/cincheo/jsweet/blob/develop/transpiler/src/main/java/org/jsweet/transpiler/extension/Java2TypeScriptAdapter.java#L1271)

but AFAIR you cannot expect to create instances dynamically with newInstance.

Please also read: https://github.com/cincheo/jsweet/blob/master/doc/jsweet-language-specifications.md#allowed-java-objects