Add support for JsType class in UIBinder.

Using a Java class annotated with JsType in UIBinder throws a 
ClassCastException because the generated code try to cast From Element 
to the JsType.


Change-Id: Ib561fb9461e2a672f1ea2608e8a458d67feb4ae3
diff --git a/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java b/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
index 88703d1..6d22169 100644
--- a/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
+++ b/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
@@ -336,7 +336,7 @@
       if (!rawType.isAssignableTo(getDomElement(typeOracle))
           && rawType.getAnnotation(jsinterop.annotations.JsType.class) != null) {
         w.write(
-            "this.owner.%1$s = (%2$s) %1$s;", name,
+            "this.owner.%1$s = (%2$s) (Object) %1$s;", name,
             rawType.getQualifiedSourceName());
       } else {
         w.write("this.owner.%1$s = %1$s;", name);
diff --git a/user/test/com/google/gwt/uibinder/test/client/TestJsElementType.java b/user/test/com/google/gwt/uibinder/test/client/TestJsElementType.java
index 3fca08c..f0ef2ad 100644
--- a/user/test/com/google/gwt/uibinder/test/client/TestJsElementType.java
+++ b/user/test/com/google/gwt/uibinder/test/client/TestJsElementType.java
@@ -19,7 +19,7 @@
 import jsinterop.annotations.JsType;
 
 /**
- * Test class for checking UiBinder casting to a JsType like this one.
+ * Test class for checking UiBinder casting to a JsType interface like this one.
  */
 @JsType(isNative = true)
 public interface TestJsElementType {
diff --git a/user/test/com/google/gwt/uibinder/test/client/TestJsElementTypeClass.java b/user/test/com/google/gwt/uibinder/test/client/TestJsElementTypeClass.java
new file mode 100644
index 0000000..ee37ab3
--- /dev/null
+++ b/user/test/com/google/gwt/uibinder/test/client/TestJsElementTypeClass.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2014 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
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.uibinder.test.client;
+
+import jsinterop.annotations.JsPackage;
+import jsinterop.annotations.JsProperty;
+import jsinterop.annotations.JsType;
+
+/**
+ * Test class for checking UiBinder casting to a JsType class like this one.
+ */
+@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
+public class TestJsElementTypeClass {
+  @JsProperty
+  public native String getTagName();
+}
diff --git a/user/test/com/google/gwt/uibinder/test/client/UiBinderJsInteropTest.java b/user/test/com/google/gwt/uibinder/test/client/UiBinderJsInteropTest.java
index 6eee61a..57e5200 100644
--- a/user/test/com/google/gwt/uibinder/test/client/UiBinderJsInteropTest.java
+++ b/user/test/com/google/gwt/uibinder/test/client/UiBinderJsInteropTest.java
@@ -32,6 +32,7 @@
     interface Binder extends UiBinder<Widget, MyWidgetBasedUi> { }
 
     @UiField TestJsElementType myJsElementType;
+    @UiField TestJsElementTypeClass myJsElementTypeClass;
 
     @Override
     protected void init() {
@@ -40,9 +41,10 @@
     }
   }
 
-  public void testJsElementType() {
+  public void testJsElementTypes() {
     MyWidgetBasedUi widget = new MyWidgetBasedUi();
     assertEquals("JS-ELEMENT-TYPE", widget.myJsElementType.getTagName());
+    assertEquals("JS-ELEMENT-TYPE-CLASS", widget.myJsElementTypeClass.getTagName());
   }
 
   @Override
diff --git a/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml b/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
index 5aabf69..3a0e250 100644
--- a/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
+++ b/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
@@ -712,6 +712,7 @@
 
      <element-with-tagname ui:field='myElementWithTagName'/>
      <js-element-type ui:field='myJsElementType'/>
+     <js-element-type-class ui:field='myJsElementTypeClass'/>
      <demo:FooIsWidget ui:field='fooIsWidget' addStyleNames="{myStyle.menuBar}" visible="false" />
    </gwt:HTMLPanel>
   </gwt:Dock>