Reviewers: Ray Ryan,

Description:
Uses the java.beans.Introspector#decapitalize instead of "manual
decapitalization" of setter-method names to attribute names.
This means setHTML() can be set using an all-caps HTML="" attribute,
instead of hTML="". This applies to all all-caps setters (actually,
decapitalize won't lowercase the first char if it is followed by another
upper-case char, which means an hypothetical setIFrameName setter for
instance wouldn't be changed to iFrameName but kept as IFrameName).

This is a breaking change (for those who use hTML=""). It could be made
to accept both hTML="" and HTML="" (or iFrameName and IFrameName) if you
prefer.

Testing done: run the com.google.gwt.uibinder.All suite (in  dev mode
only; as there's no reason it would have behaved different in prod mode
since this is all about code generation; I actually tried prod mode but
faced a StackOverflowException).

Ray, assigned to you as you're the one to blame for the original code
;-)

Please review this at http://gwt-code-reviews.appspot.com/642801/show

Affected files:
  user/src/com/google/gwt/uibinder/rebind/model/OwnerFieldClass.java
  user/test/com/google/gwt/uibinder/rebind/model/OwnerFieldClassTest.java


Index: user/src/com/google/gwt/uibinder/rebind/model/OwnerFieldClass.java
===================================================================
--- user/src/com/google/gwt/uibinder/rebind/model/OwnerFieldClass.java (revision 8277) +++ user/src/com/google/gwt/uibinder/rebind/model/OwnerFieldClass.java (working copy)
@@ -25,6 +25,7 @@
 import com.google.gwt.uibinder.client.UiConstructor;
 import com.google.gwt.uibinder.rebind.MortalLogger;

+import java.beans.Introspector;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -190,8 +191,7 @@
       String propertyName = method.getName().substring(3);

       // turn "PropertyName" into "propertyName"
-      propertyName = propertyName.substring(0, 1).toLowerCase()
-          + propertyName.substring(1);
+      propertyName = Introspector.decapitalize(propertyName);

       Collection<JMethod> propertyMethods = allSetters.get(propertyName);
       if (propertyMethods == null) {
Index: user/test/com/google/gwt/uibinder/rebind/model/OwnerFieldClassTest.java
===================================================================
--- user/test/com/google/gwt/uibinder/rebind/model/OwnerFieldClassTest.java (revision 8277) +++ user/test/com/google/gwt/uibinder/rebind/model/OwnerFieldClassTest.java (working copy)
@@ -25,7 +25,7 @@
 import com.google.gwt.uibinder.client.UiConstructor;
 import com.google.gwt.uibinder.rebind.JClassTypeAdapter;
 import com.google.gwt.uibinder.rebind.MortalLogger;
-import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.HTML;

 import junit.framework.TestCase;

@@ -44,22 +44,25 @@
   }

   public void testOwnerFieldClass() throws Exception {
-    // Get the JType for a Label
-    JClassType labelType = gwtTypeAdapter.adaptJavaClass(Label.class);
+    // Get the JType for a HTML
+    JClassType htmlType = gwtTypeAdapter.adaptJavaClass(HTML.class);

     // Now get its field class model
-    OwnerFieldClass fieldClass = OwnerFieldClass.getFieldClass(labelType,
+    OwnerFieldClass fieldClass = OwnerFieldClass.getFieldClass(htmlType,
         MortalLogger.NULL);

     // Check the class model properties
-    assertEquals(labelType, fieldClass.getRawType());
+    assertEquals(htmlType, fieldClass.getRawType());
     assertNull(fieldClass.getUiConstructor());

-    JMethod setter = fieldClass.getSetter("visible");
-    assertMethod(setter, "setVisible", JPrimitiveType.BOOLEAN);
+    JMethod visibleSetter = fieldClass.getSetter("visible");
+    assertMethod(visibleSetter, "setVisible", JPrimitiveType.BOOLEAN);

+    JMethod htmlSetter = fieldClass.getSetter("HTML");
+ assertMethod(htmlSetter, "setHTML", gwtTypeAdapter.adaptJavaClass(String.class));
+
     // Check that the same instance of the model is returned if asked again
-    assertSame(fieldClass, OwnerFieldClass.getFieldClass(labelType,
+    assertSame(fieldClass, OwnerFieldClass.getFieldClass(htmlType,
         MortalLogger.NULL));

     gwtTypeAdapter.verifyAll();


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

Reply via email to