Monday, July 20, 2015

@GwtUnreachable annotation

Hi.

I haven't found an easy solution to this problem: a function, written in java, should call different implementation when used from browser and from server code. E. g.

===
void download(String url) {
    if (GWT.isClient()) {
        downloadNative(url);
    } else {
        downloadJre(url);
    }
}

native void downloadNative(String url) /*-{ ... }-*/);

void downloadJre(String url) {
    ...
}
===

This doesn't work if `downloadJre` references classes not available in GWT (netty, for example).

There's a solution, use super-source to override `downloadJre` implementation with dummy implementation that does nothing. However, I think it is inconvenient.

I'm thinking about easier to use alternative: @GwtUnreachable annotation.

GWT has @GwtIncompatible annotation. When function is marked as @GwtIncompatible, GWT just does not see it.

@GwtUnreachable annotation should be somewhat similar: when GWT compiler encounters a function that is marked as @GwtUnreachable, it parses it as a function with body `throw new IllStateException("unreachable")`

E. g. in the example above `downloadJre` function will be visible to GWT as a function that unconditionally throws, thus it is successfully parsed and validated, and that function is later dropped by the GWT optimizer.

Any thoughts?

--
Stepan Koltsov

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" 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