Monday, July 20, 2015

Re: @GwtUnreachable annotation

On Monday, July 20, 2015 at 6:26:39 PM UTC+3, Jens wrote:
Why does @GwtIncompatible doesn't work for you? The result is the same as your proposed @GwtUnreachable annotation.

It just doesn't work. My code is:

```
import com.google.gwt.core.shared.GwtIncompatible;
import com.google.gwt.core.shared.GWT;

...

    @GwtIncompatible("")
    private void downloadJre() {
        // empty
    }

    private void download() {
        if (!GWT.isClient()) {
            downloadJre();
        }
    }
```
 
results in error like this: https://gist.github.com/stepancheg/bd4a66d3ca8c893521f3 (At least in GWT 2.7.0 superdevmode)

The error is the same as if `downloadJre()` was non-existent method.

And my understanding is that it should work that way according to GwtIncompatible javadoc: GWT just does not see function annotated with @GwtIncompatible.
 
 
You might need to refactor your code a bit if GWT complains about imports used by downloadJre()
but that would probably be the same case for @GwtUnreachable. I used @GwtIncompatible once to avoid super-source and it did the job just fine (used it for some shared number format class).

Also instead of super sourcing no-op implementations for everything that downloadJre() uses (but GWT does not support), you should super source the whole download() method. Basically you implement the download() method once for a JRE environment and then provide a super sourced version of download() that works in the browser with GWT. Because your download() method is probably in a larger class you should refactor it out into its own class so you only need to super source as less code as possible.

That should work, but harder to maintain that simple if+annotation.

--
Stepan

--
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