cincheo / jsweet

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

babylonjs--babylon candy issue #93

Closed ssatguru closed 8 years ago

ssatguru commented 8 years ago

babylon.d.ts defines the class "DirectionalLight" as

class DirectionalLight extends Light implements IShadowLight 

JSweet defines this class as

public class DirectionalLight extends Light

"implements IShadowLight " is missing

ssatguru commented 8 years ago

Interface issue ?

renaudpawlak commented 8 years ago

OK. I finally took the time to look into this issue. There was actually a bug (well, let's say not-supported-yet feature) in the case where a class extends another class and some interfaces. This bug is fixed, so now JSweet behaves as expected for this DirectionalLight case. Normally I have republished the candy, so that it should now be up-to-date.

The output requires some explanations. If you look at the code, you will see that the DirectionalLightclass does not actually implements the IShadowLight, but it instead:

  1. injects all the IShadowLight members to DirectionalLight,
  2. adds the @Extends({IShadowLight.class}) annotation.

This is because in JSweet, interfaces can be defined as classes (annotated with @Interface) in order to allow fields in interfaces (like in TS). So, since multiple inheritance of classes is not allowed in Java, we implement some sort of mixins here. What you get in the end is the same API except that the super interfaces have been inlined in the child ones (in case of multiple inheritance only). The @Extends annotation keeps track of the inlining that was done.

Note that the @Extends annotation will allow us to implement the instanceof operator correctly in the coming releases (not yet done but not too complicated to do).