Java template changes for new RPC error types.

Use the * import wildcard so that we don't miss required imports.

Also swap the order of exeception causes so that the outer is the RPC
error type. This is done so that we can catch() the exception instead of
using:
if (exection.cause() instanceof ErrFoo)

Change-Id: If132a3feebfb58be8b12a8ffa61927b85b9da227
diff --git a/tools/codergen/template/embed.go b/tools/codergen/template/embed.go
index e01ac79..ba8cd75 100644
--- a/tools/codergen/template/embed.go
+++ b/tools/codergen/template/embed.go
@@ -1267,18 +1267,18 @@

   import org.jetbrains.annotations.NotNull;¶

-  import com.android.tools.rpclib.binary.BinaryClass;¶
-  import com.android.tools.rpclib.binary.BinaryID;¶
-  import com.android.tools.rpclib.binary.BinaryObject;¶
-  import com.android.tools.rpclib.binary.Decoder;¶
-  import com.android.tools.rpclib.binary.Encoder;¶
-  import com.android.tools.rpclib.binary.Namespace;¶
+  import com.android.tools.rpclib.binary.*;¶
+  import com.android.tools.rpclib.schema.*;¶
   {{range .Struct.Fields}}{{Call "Java.Import" .Type}}{{end}}

   import java.io.IOException;¶

   {{if .Struct.Exported}}public•{{end}}
-  final class {{File.ClassName .Struct}} implements BinaryObject {Ȧ
+  final class {{File.ClassName .Struct}}
+  {{range .Struct.Implements}}
+    {{if and (eq .Package "rpc") (eq .Name "Err")}}•extends RpcException{{end}}
+  {{end}}
+  •implements BinaryObject {»¶
     //{{Section "Java.ClassBody"}}¶
     public enum Klass implements BinaryClass {Ȧ
       //{{Section "Java.KlassBody"}}¶
@@ -1286,7 +1286,6 @@
   «}¶
 {{end}}
 
-
 {{define "Java.FactoryBody"}}
   ¶{{/*Newline after section marker*/}}
   {{range .Structs}}{{File.ClassName .}}.register();¶{{end}}
@@ -1466,7 +1465,7 @@
     {{range .Service.Methods}}
       private class {{.Name}}Callable implements {{Call "Java.Callable" .Result.Type}} {Ȧ
         private final {{File.ClassName .Call}} myCall;¶
-        private final Exception stack = new StackException();¶
+        private final Exception myStack = new StackException();¶

         private {{.Name}}Callable({{template "Java.Parameters" .}}) {Ȧ
           myCall = new {{File.ClassName .Call}}();¶
@@ -1484,7 +1483,8 @@
               return null;¶
             {{end}}
           «} catch (Exception e) {»¶
-            throw (Exception)stack.initCause(e);¶
+            e.initCause(myStack);¶
+            throw e;¶
           «}¶
         «}¶
       «}¶
diff --git a/tools/codergen/template/java_binary.tmpl b/tools/codergen/template/java_binary.tmpl
index 1e1269e..a70b444 100644
--- a/tools/codergen/template/java_binary.tmpl
+++ b/tools/codergen/template/java_binary.tmpl
@@ -195,18 +195,18 @@

   import org.jetbrains.annotations.NotNull;¶

-  import com.android.tools.rpclib.binary.BinaryClass;¶
-  import com.android.tools.rpclib.binary.BinaryID;¶
-  import com.android.tools.rpclib.binary.BinaryObject;¶
-  import com.android.tools.rpclib.binary.Decoder;¶
-  import com.android.tools.rpclib.binary.Encoder;¶
-  import com.android.tools.rpclib.binary.Namespace;¶
+  import com.android.tools.rpclib.binary.*;¶
+  import com.android.tools.rpclib.schema.*;¶
   {{range .Struct.Fields}}{{Call "Java.Import" .Type}}{{end}}

   import java.io.IOException;¶

   {{if .Struct.Exported}}public•{{end}}
-  final class {{File.ClassName .Struct}} implements BinaryObject {Ȧ
+  final class {{File.ClassName .Struct}}
+  {{range .Struct.Implements}}
+    {{if and (eq .Package "rpc") (eq .Name "Err")}}•extends RpcException{{end}}
+  {{end}}
+  •implements BinaryObject {»¶
     //{{Section "Java.ClassBody"}}¶
     public enum Klass implements BinaryClass {Ȧ
       //{{Section "Java.KlassBody"}}¶
@@ -214,7 +214,6 @@
   «}¶
 {{end}}
 
-
 {{define "Java.FactoryBody"}}
   ¶{{/*Newline after section marker*/}}
   {{range .Structs}}{{File.ClassName .}}.register();¶{{end}}
diff --git a/tools/codergen/template/java_client.tmpl b/tools/codergen/template/java_client.tmpl
index 66275e3..f11159e 100644
--- a/tools/codergen/template/java_client.tmpl
+++ b/tools/codergen/template/java_client.tmpl
@@ -83,7 +83,7 @@
     {{range .Service.Methods}}
       private class {{.Name}}Callable implements {{Call "Java.Callable" .Result.Type}} {Ȧ
         private final {{File.ClassName .Call}} myCall;¶
-        private final Exception stack = new StackException();¶
+        private final Exception myStack = new StackException();¶

         private {{.Name}}Callable({{template "Java.Parameters" .}}) {Ȧ
           myCall = new {{File.ClassName .Call}}();¶
@@ -101,7 +101,8 @@
               return null;¶
             {{end}}
           «} catch (Exception e) {»¶
-            throw (Exception)stack.initCause(e);¶
+            e.initCause(myStack);¶
+            throw e;¶
           «}¶
         «}¶
       «}¶