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
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6481 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java b/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java
index 57f0393..0d639da 100644
--- a/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java
+++ b/user/src/com/google/gwt/uibinder/parsers/MenuItemParser.java
@@ -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 "";
- }
-
- return null;
- }
-
- 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");
+ writer.getOracle().findType(MenuItem.class.getName()), "\"\"",
+ "(com.google.gwt.user.client.Command) null");
- InterpreterPipe<String> interpreter = new InterpreterPipe<String>();
+ final JClassType menuBarType = writer.getOracle().findType(
+ MenuBar.class.getCanonicalName());
- // 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.
+ class MenuBarInterpreter implements Interpreter<Boolean> {
+ String menuBarField = null;
- final HtmlInterpreter htmlInterpreter =
- HtmlInterpreter.newInterpreterForUiObject(writer, fieldName);
- MenuItemGutsInterpreter guts =
- new MenuItemGutsInterpreter(writer, elem.getNamespaceUri(),
- elem.toString(), htmlInterpreter);
+ public Boolean interpretElement(XMLElement child)
+ throws UnableToCompleteException {
- interpreter.add(guts);
- interpreter.add(htmlInterpreter);
+ 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;
+ }
- String html = elem.consumeInnerHtml(interpreter);
- if (html.trim().length() > 0) {
- writer.genStringPropertySet(fieldName, "HTML", html);
+ return false;
+ }
+
+ boolean isMenuBar(XMLElement child) throws UnableToCompleteException {
+ return menuBarType.equals(writer.findFieldType(child));
+ }
}
- 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);
}
}
}
diff --git a/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java b/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
index e9552d9..3936155 100644
--- a/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
+++ b/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
@@ -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;