Monday, July 20, 2015

Re: @GwtUnreachable annotation

On Monday, July 20, 2015 at 9:12:55 PM UTC+3, Jens wrote:
Hmm looks like a bug and/or bad error reporting. I could imagine that it fails because you have code calling the @GwtIncompatible method. Yes it is not called at runtime but the AST maintained by the compiler at compile time might be broken now. I think your code must not be broken once @GwtIncompatible code has been removed.

I don't think so. If code must not be broken without @GwtIncompatible, what's the point of having the annotation?

What I did in my code was to implement a client version of the method and then override that method in a sub class to provide a JRE version. I have then marked that overridden method as incompatible. So when the compiler does not see the overridden JRE method then the calling code is still valid.

So maybe try something like:

void download() {
 
Downloader downloader;
 
if (GWT.isClient()) {
    downloader = 
new GwtDownloader();
  } else {
    downloader = 
new JreDownloader();
 
}
  downloader.download();
}

// should NOT be abstract, because code would be invalid if JreDownloader.download() is not seen by the compiler
class Downloader {
 
void download() {
   
// no-op
 
}
}

class GwtDownloader extends Downloader {
  @Override
 
void download() {
   
// GWT version
 
}
}

class JreDownloader extends Downloader {
 
// When this method is not seen by the Compiler all code is still valid, as the no-op method would be called. 
  // (it would not turn red in your IDE if you would delete that overridden method)

 
@GwtIncompatible
 
@Override
 
void download() {
   
// JRE version
 
}
}


Does that help?

Surprisingly, yes. Thanks!

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