I was thinking more simply about wrapping the whole
getDelegatesByPath/getEditorByPath/fallback, starting at line 131, into
a loop:

boolean found = false;
do {
  // Find the leaf editor's delegate.
  List<AbstractEditorDelegate<?, ?>> leafDelegates =
delegateMap.getDelegatesByPath(absolutePath);
  List<Editor<?>> editors = delegateMap.getEditorByPath(absolutePath);
  if (leafDelegates != null) {
    // ...
    found = true;
  } else if (editors != null) {
    // ...
    found = true;
  } else {
    // try with a shorter path:
    int dotPos = absolutePath.lastIndexOf('.');
    if (dotPos > 0) {
      absolutePath = absolutePath.substring(0, ditPos);
    } else {
      absolutePath = "";
    }
  }
} while (!found);

IIRC, there should always be an editor for path "", so we're sure we'll
never have an infinite loop.
To make sure, we could change the 'absolutePath=""' to a 'break', and
add an 'if (!found)' after the loop to recordEditor on the top-level
editor.

In the most common case, there will always be a single iteration of the
do/while loop, so it won't cost much.

What do you think?


http://gwt-code-reviews.appspot.com/1727807/diff/3002/user/test/com/google/gwt/editor/client/EditorErrorTest.java
File user/test/com/google/gwt/editor/client/EditorErrorTest.java
(right):

http://gwt-code-reviews.appspot.com/1727807/diff/3002/user/test/com/google/gwt/editor/client/EditorErrorTest.java#newcode292
user/test/com/google/gwt/editor/client/EditorErrorTest.java:292: return
new ConstraintViolationImpl.Builder<T>()
FYI, could also be written:

   return ConstraintViolationImpl.<T>builder()
     .setMessage(msg)
     ...
     .build();

http://gwt-code-reviews.appspot.com/1727807/diff/3002/user/test/com/google/gwt/editor/client/EditorErrorTest.java#newcode295
user/test/com/google/gwt/editor/client/EditorErrorTest.java:295:
.setPropertyPath(new Path() {
Could be written using c.g.g.validation.client.impl.PathImpl:

Path createPath(String[] segments) {
  PathImpl path = new PathImpl();
  for (String segment : segments) {
    path = path.append(segment);
  }
  return path;
}

And passing a String... or String[] to createViolation.

http://gwt-code-reviews.appspot.com/1727807/

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

Reply via email to