Thursday, December 3, 2015

Re: native JsType with constants

Ignoring initialization is quite complicated when you put in to account generated clinit and also primitives which becomes compile-time-constants per jls and automatically inlined. Also code wise it is quite weird and potentially confusing.

Workaround is quite simple, just remove the "final" keyword and you are set.


On Thu, Dec 3, 2015 at 5:35 AM, Jens <jens.nehlmeier@gmail.com> wrote:

Awesome. Thank you. @JsOverlay did the trick.

But IMHO @JsOverlay is only a workaround because it is meant to be used for code additions that do not exist in the underlying native type. So in your case GWT will now generate some additional code for your constants and will not use $wnd.Node.ELEMENT_NODE when doing comparisons. The link Thomas has posted is a good example of proper JsOverlay usage as the constant "TAG" is not part of the underlying native object.

So I would consider it a bug/missing feature that you can not define native constants in a native JsType. IMHO the restriction checker should allow static final constant initialization in native JsType and if constant is not annotated with @JsOverlay then GWT should treat the constant name as native constant. The value to initialize the constant in java code should be ignored, as initialization only exists to make java happy. 

cc @goktug

-- J.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment