Fix code-generation error in ProxyCreator when an RPC async method returns a Request object.
Add a test for this use-case.

Patch by: bobv
Review by: mmendez (TBR)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2222 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
index 3372e3d..8d35f8a 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
@@ -305,10 +305,6 @@
     }
 
     w.println();
-    if (asyncReturnType != JPrimitiveType.VOID) {
-      w.print("return ");
-    }
-
     w.println("String payload = " + streamWriterName + ".toString();");
 
     w.println("boolean toss2 = isStatsAvailable() && stats(\""
@@ -316,6 +312,10 @@
         + getProxySimpleName() + "." + syncMethod.getName()
         + "\", getRequestId()));");
 
+    if (asyncReturnType != JPrimitiveType.VOID) {
+      w.print("return ");
+    }
+
     // Call the doInvoke method to actually send the request.
     w.print("doInvoke(");
     JType returnType = syncMethod.getReturnType();
diff --git a/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java b/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java
index 354c86f..05bec77 100644
--- a/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java
+++ b/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -16,6 +16,7 @@
 package com.google.gwt.user.client.rpc;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.http.client.Request;
 import com.google.gwt.junit.client.GWTTestCase;
 
 /**
@@ -33,6 +34,7 @@
  */
 public class RemoteServiceServletTest extends GWTTestCase {
   private static final int TEST_DELAY = Integer.MAX_VALUE;
+  private Request req;
 
   private static RemoteServiceServletTestServiceAsync getAsyncService() {
     RemoteServiceServletTestServiceAsync service = (RemoteServiceServletTestServiceAsync) GWT.create(RemoteServiceServletTestService.class);
@@ -52,15 +54,17 @@
 
     delayTestFinish(TEST_DELAY);
 
-    service.test(new AsyncCallback() {
+    req = service.test(new AsyncCallback<Object>() {
 
       public void onFailure(Throwable caught) {
         TestSetValidator.rethrowException(caught);
       }
 
       public void onSuccess(Object result) {
+        assertTrue(!req.isPending());
         finishTest();
       }
     });
+    assertTrue(req.isPending());
   }
 }
diff --git a/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java b/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java
index 82e166d..0576df3 100644
--- a/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java
+++ b/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -15,9 +15,11 @@
  */
 package com.google.gwt.user.client.rpc;
 
+import com.google.gwt.http.client.Request;
+
 /**
  * TODO: document me.
  */
 public interface RemoteServiceServletTestServiceAsync {
-  void test(AsyncCallback callback);
+  Request test(AsyncCallback callback);
 }