Revision: 6568
Author: fabb...@google.com
Date: Fri Oct 30 13:26:53 2009
Log: Merge 6481, Just remembered that MenuItemParser has support for the old
phantom MenuItemHTML child, which I killed off like a year ago. Getting
rid of that support drastically simplifies the class.

It also revealed a bug in UiBinderWriter#getClassHierarchyBreadthFirst: it
was actually depth first, leading primitive parsers like UiObjectParser to
fire before higher level stuff like HasHTMLParser.

Reviewed by jgw


http://code.google.com/p/google-web-toolkit/source/detail?r=6568

Modified:
   
/branches/snapshot-2009.10.23-r6446/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java
   
/branches/snapshot-2009.10.23-r6446/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java

=======================================
---  
/branches/snapshot-2009.10.23-r6446/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java
         
Tue Sep  1 15:14:29 2009
+++  
/branches/snapshot-2009.10.23-r6446/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java
         
Fri Oct 30 13:26:53 2009
@@ -1,12 +1,12 @@
  /*
   * Copyright 2009 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
@@ -19,6 +19,8 @@
  import com.google.gwt.core.ext.typeinfo.JClassType;
  import com.google.gwt.uibinder.rebind.UiBinderWriter;
  import com.google.gwt.uibinder.rebind.XMLElement;
+import com.google.gwt.uibinder.rebind.XMLElement.Interpreter;
+import com.google.gwt.user.client.ui.MenuBar;
  import com.google.gwt.user.client.ui.MenuItem;

  /**
@@ -26,98 +28,43 @@
   */
  public class MenuItemParser implements ElementParser {

-  /**
-   * Used by {...@link XMLElement#consumeInnerHtml}. Gets to examine
-   * each dom element. Removes gwt:MenuBar elements and hands them
-   * to the template writer to be interpreted as widgets. Replaces
-   * gwt:MenuItemHTML elements with their consumeInnerHtml contents,
-   * and warns that they are deprecated.
-   */
-  private static class MenuItemGutsInterpreter
-      implements XMLElement.Interpreter<String> {
-    private final String namespaceUri;
-    private final HtmlInterpreter htmlInterpreter;
-    private final UiBinderWriter writer;
-    private final String errorContext;
-
-    private String menuBarField;
-
-    public MenuItemGutsInterpreter(UiBinderWriter writer, String  
namespaceUri,
-        String errorContext, HtmlInterpreter htmlInterpreter) {
-      this.writer = writer;
-      this.errorContext = errorContext;
-      this.namespaceUri = namespaceUri;
-      this.htmlInterpreter = htmlInterpreter;
-    }
-
-    public String interpretElement(XMLElement elem)
-        throws UnableToCompleteException {
-      if (isMenuHtml(elem)) {
-        writer.warn("In %s, the MenuItemHTML element is no longer  
required, "
-            + "and its contents have been inlined. This will become an  
error.",
-            errorContext);
-        return elem.consumeInnerHtml(htmlInterpreter);
-      }
-
-      if (isMenuBar(elem)) {
-        if (menuBarField != null) {
-          writer.die("In %s, only one MenuBar may be contained in a  
MenuItem",
-              errorContext);
-        }
-        menuBarField = writer.parseElementToField(elem);
-        return "";
+  public void parse(final XMLElement elem, String fieldName, JClassType  
type,
+      final UiBinderWriter writer) throws UnableToCompleteException {
+    writer.setFieldInitializerAsConstructor(fieldName,
+        writer.getOracle().findType(MenuItem.class.getName()), "\"\"",
+        "(com.google.gwt.user.client.Command) null");
+
+    final JClassType menuBarType = writer.getOracle().findType(
+        MenuBar.class.getCanonicalName());
+
+    class MenuBarInterpreter implements Interpreter<Boolean> {
+      String menuBarField = null;
+
+      public Boolean interpretElement(XMLElement child)
+          throws UnableToCompleteException {
+
+        if (isMenuBar(child)) {
+          if (menuBarField != null) {
+            writer.die(
+                "In %s, only one MenuBar may be contained in a MenuItem",  
elem);
+          }
+          menuBarField = writer.parseElementToField(child);
+          return true;
+        }
+
+        return false;
        }

-      return null;
+      boolean isMenuBar(XMLElement child) throws UnableToCompleteException  
{
+        return menuBarType.equals(writer.findFieldType(child));
+      }
      }

-    String getMenuBarField() {
-      return menuBarField;
-    }
-
-    private boolean isMenuBar(XMLElement child) {
-      return namespaceUri.equals(child.getNamespaceUri())
-          && child.getLocalName().equals(TAG_MENUBAR);
-    }
-
-    private boolean isMenuHtml(XMLElement child) {
-      return namespaceUri.equals(child.getNamespaceUri())
-          && child.getLocalName().equals(TAG_MENUITEMHTML);
-    }
-  }
-  private static final String TAG_MENUBAR = "MenuBar";
-
-  private static final String TAG_MENUITEMHTML = "MenuItemHTML";
-
-  public void parse(final XMLElement elem, String fieldName, JClassType  
type,
-      final UiBinderWriter writer) throws UnableToCompleteException {
-    writer.setFieldInitializerAsConstructor(fieldName,
-        writer.getOracle().findType(MenuItem.class.getName()),
-        "\"\"", "(com.google.gwt.user.client.Command) null");
-
-    InterpreterPipe<String> interpreter = new InterpreterPipe<String>();
-
-    // Build an interpreter pipeline to handle MenuItemHTML and MenuBar
-    // children, and to interpret everything other than those as HTML.
-    // TODO(rjrjr) Once MenuItemHTML goes away, we can reduce this to
-    // just handling MenuBar, and rely on HasHTMLParser to do the
-    // "everything other than those" bit.
-
-    final HtmlInterpreter htmlInterpreter =
-        HtmlInterpreter.newInterpreterForUiObject(writer, fieldName);
-    MenuItemGutsInterpreter guts =
-        new MenuItemGutsInterpreter(writer, elem.getNamespaceUri(),
-            elem.toString(), htmlInterpreter);
-
-    interpreter.add(guts);
-    interpreter.add(htmlInterpreter);
-
-    String html = elem.consumeInnerHtml(interpreter);
-    if (html.trim().length() > 0) {
-      writer.genStringPropertySet(fieldName, "HTML", html);
-    }
-    if (guts.getMenuBarField() != null) {
-      writer.genPropertySet(fieldName, "subMenu", guts.getMenuBarField());
+    MenuBarInterpreter interpreter = new MenuBarInterpreter();
+    elem.consumeChildElements(interpreter);
+
+    if (interpreter.menuBarField != null) {
+      writer.genPropertySet(fieldName, "subMenu",  
interpreter.menuBarField);
      }
    }
  }
=======================================
---  
/branches/snapshot-2009.10.23-r6446/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
  
Fri Oct 16 13:11:56 2009
+++  
/branches/snapshot-2009.10.23-r6446/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
  
Fri Oct 30 13:26:53 2009
@@ -176,14 +176,15 @@
        JClassType curType = q.removeFirst();
        list.add(curType);

-      // Add the superclass and implemented interfaces to the back of the  
queue.
+      // Add implemented interfaces to the back of the queue (breadth  
first, remember?)
+      for (JClassType intf : curType.getImplementedInterfaces()) {
+        q.add(intf);
+      }
+      // Add then add superclasses
        JClassType superClass = curType.getSuperclass();
        if (superClass != null) {
          q.add(superClass);
        }
-      for (JClassType intf : curType.getImplementedInterfaces()) {
-        q.add(intf);
-      }
      }

      return list;

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

Reply via email to