Revision: 9934
Author:   [email protected]
Date:     Sun Apr  3 21:22:18 2011
Log:      Made UiBinder class lookup more generous.
Previously <gwt:foo.Bar would look for class foo with inner class Bar.
Now it also looks for package foo containing class Bar.

Review at http://gwt-code-reviews.appspot.com/1386803

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9934

Modified:
 /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
 /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml

=======================================
--- /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Wed Mar 9 09:01:28 2011 +++ /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Sun Apr 3 21:22:18 2011
@@ -517,19 +517,29 @@
     }

     String ns = elem.getNamespaceUri();
-
-    JPackage pkg = parseNamespacePackage(ns);
-    if (pkg == null) {
-      throw new RuntimeException("No such package: " + ns);
-    }
-
-    JClassType rtn = null;
-    rtn = pkg.findType(tagName);
-    if (rtn == null) {
-      die(elem, "No class matching \"%s\" in %s", tagName, ns);
-    }
-
-    return rtn;
+    String packageName = ns;
+    String className = tagName;
+
+    while (true) {
+      JPackage pkg = parseNamespacePackage(packageName);
+      if (pkg == null) {
+        throw new RuntimeException("No such package: " + packageName);
+      }
+
+      JClassType rtn = pkg.findType(className);
+      if (rtn != null) {
+        return rtn;
+      }
+
+ // Try again: shift one element of the class name onto the package name.
+      // If the class name has only one element left, fail.
+      int index = className.indexOf(".");
+      if (index == -1) {
+        die(elem, "No class matching \"%s\" in %s", tagName, ns);
+      }
+      packageName = packageName + "." + className.substring(0, index);
+      className = className.substring(index + 1);
+    }
   }

   /**
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml Fri Apr 1 10:25:12 2011 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml Sun Apr 3 21:22:18 2011
@@ -47,6 +47,8 @@

 <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
   xmlns:gwt='urn:import:com.google.gwt.user.client.ui'
+  xmlns:gwt2='urn:import:com.google.gwt.user.client'
+  xmlns:gwt3='urn:import:com'
   xmlns:demo='urn:import:com.google.gwt.uibinder.test.client'

xmlns:legacyValuesForBeans='urn:with:com.google.gwt.uibinder.test.client.WidgetBasedUi.FakeBundle2'
@@ -665,9 +667,9 @@
   <gwt:DateLabel ui:field='myDateLabel2' format='{MY_DATE_FORMAT}' />

<gwt:NumberLabel ui:field='myNumberLabel' predefinedFormat='SCIENTIFIC' />
-  <gwt:NumberLabel ui:field='myNumberLabel2' format='{MY_NUMBER_FORMAT}' />
-
-  <gwt:ValueLabel ui:field='myValueLabel' renderer='{doubleRenderer}' />
+ <gwt2:ui.NumberLabel ui:field='myNumberLabel2' format='{MY_NUMBER_FORMAT}' />
+
+ <gwt3:google.gwt.user.client.ui.ValueLabel ui:field='myValueLabel' renderer='{doubleRenderer}' />

   <img src="{values.aUrl}" ui:field='myImage'/>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to