Reviewers: rjrjr, bobv,

Description:
Issue 6066:     RequestFactoryEditorDriver failing to collect dotted path in
@Path annotation

http://code.google.com/p/google-web-toolkit/issues/detail?id=6066

PathCollection only ignores a path when the edited type is a value type
AND the absolute path does not contain a dot. In this case, if the
edited type is a value type, the path before the last dot is
"collected".

In the unit test, the barName subeditor (with @Path("barField.userName")
annotation) worked (i.e. barField was retrieved) because there also is a
subeditor for barField; the path came from that one and not from the
barName subeditor (see the change in the order of the returned paths).
The actual test though is with the subeditor used in the ListEditor,
which only defines a barName subeditor.

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

Affected files:
  M user/src/com/google/gwt/requestfactory/client/impl/PathCollector.java
  M user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java


Index: user/src/com/google/gwt/requestfactory/client/impl/PathCollector.java
diff --git a/user/src/com/google/gwt/requestfactory/client/impl/PathCollector.java b/user/src/com/google/gwt/requestfactory/client/impl/PathCollector.java index e654e416d0b21216a628cb3c24c386db22e8baa3..5e67ac3e560ad0f75bf1a0c22ac82d39b2a62720 100644
--- a/user/src/com/google/gwt/requestfactory/client/impl/PathCollector.java
+++ b/user/src/com/google/gwt/requestfactory/client/impl/PathCollector.java
@@ -41,8 +41,16 @@ class PathCollector extends EditorVisitor {

   public <T> boolean visit(EditorContext<T> ctx) {
     String path = ctx.getAbsolutePath();
-    if (path.length() > 0 && !ValueCodex.canDecode(ctx.getEditedType())) {
-      paths.add(path);
+    if (path.length() > 0) {
+      if (!ValueCodex.canDecode(ctx.getEditedType())) {
+        paths.add(path);
+      } else {
+        int dotPosition = path.lastIndexOf('.');
+        if (dotPosition > 0) {
+          String parentPath = path.substring(0, dotPosition);
+          paths.add(parentPath);
+        }
+      }
     }
     if (ctx.asCompositeEditor() != null) {
       ctx.traverseSyntheticCompositeEditor(this);
Index: user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java
diff --git a/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java b/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java index f03fab91429ebc125508e2895df76d0d89d95fa4..42ed8ecaa8fb35e7a5e3bb6d0e71b38275794e06 100644
--- a/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java
+++ b/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java
@@ -61,8 +61,12 @@ public class EditorTest extends RequestFactoryTestBase {
     }
   }

-  static class SimpleFooBarOnlyEditor implements Editor<SimpleFooProxy> {
-    SimpleBarEditor barField = new SimpleBarEditor();
+ static class SimpleFooBarNameOnlyEditor implements Editor<SimpleFooProxy> {
+    /**
+     * Test nested path access.
+     */
+    @Path("barField.userName")
+    final SimpleEditor<String> barName = SimpleEditor.of();
   }

   interface SimpleFooDriver extends
@@ -81,10 +85,10 @@ public class EditorTest extends RequestFactoryTestBase {
     @Path("barField.userName")
     final SimpleEditor<String> barName = SimpleEditor.of();

- final ListEditor<SimpleFooProxy, SimpleFooBarOnlyEditor> selfOneToManyField = ListEditor.of(new EditorSource<SimpleFooBarOnlyEditor>() { + final ListEditor<SimpleFooProxy, SimpleFooBarNameOnlyEditor> selfOneToManyField = ListEditor.of(new EditorSource<SimpleFooBarNameOnlyEditor>() {
       @Override
-      public SimpleFooBarOnlyEditor create(int index) {
-        return new SimpleFooBarOnlyEditor();
+      public SimpleFooBarNameOnlyEditor create(int index) {
+        return new SimpleFooBarNameOnlyEditor();
       }
     });

@@ -128,8 +132,8 @@ public class EditorTest extends RequestFactoryTestBase {
     final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
     driver.initialize(req, editor);
     final String[] paths = driver.getPaths();
-    assertEquals(Arrays.asList("selfOneToManyField",
-        "selfOneToManyField.barField", "barField"), Arrays.asList(paths));
+    assertEquals(Arrays.asList("barField", "selfOneToManyField",
+        "selfOneToManyField.barField"), Arrays.asList(paths));

     req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(
         new Receiver<SimpleFooProxy>() {
@@ -155,7 +159,9 @@ public class EditorTest extends RequestFactoryTestBase {
             editor.userName.setValue("EditorFooTest");
             // When there are duplicate paths, last declared editor wins
             editor.barEditor().userName.setValue("EditorBarTest");
-            editor.barName.setValue("ignored");
+            editor.barName.setValue("ignored 1");
+            editor.selfOneToManyField.getEditors().get(0).barName.setValue(
+                "ignored 2");
             driver.flush().fire();
           }
         });
@@ -222,8 +228,8 @@ public class EditorTest extends RequestFactoryTestBase {
     driver.initialize(req, editor);

     String[] paths = driver.getPaths();
-    assertEquals(Arrays.asList("selfOneToManyField",
-        "selfOneToManyField.barField", "barField"), Arrays.asList(paths));
+    assertEquals(Arrays.asList("barField", "selfOneToManyField",
+        "selfOneToManyField.barField"), Arrays.asList(paths));

     req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(
         new Receiver<SimpleFooProxy>() {


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

Reply via email to