Reviewers: Ray Ryan, jgw, mmendez, Description: Instead of using a monotonically increasing number in UiBinderWriter.declareDomIdHolder(), makes the field name related to the field the element will be injected in (in most cases). For the case where there's a need to generate a field name (WidgetInterpreter), uses a monotonically increasing 'serial' non-static field (just like WidgetPlaceholderInterpreter does already).
I'm really not sure it really fixes the issue (I don't know enough about UiBinderGenerator yet), but it'll a priori help me in implementing an "id generator" interface. I've only run the UiBinder test cases, and they still pass with the patch applied, so at least it seems I didn't break anything. Please review this at http://gwt-code-reviews.appspot.com/78806 Affected files: user/src/com/google/gwt/uibinder/parsers/WidgetInterpreter.java user/src/com/google/gwt/uibinder/parsers/WidgetPlaceholderInterpreter.java user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Index: user/src/com/google/gwt/uibinder/parsers/WidgetInterpreter.java =================================================================== --- user/src/com/google/gwt/uibinder/parsers/WidgetInterpreter.java (revision 6341) +++ user/src/com/google/gwt/uibinder/parsers/WidgetInterpreter.java (working copy) @@ -57,6 +57,7 @@ return tag; } + private int serial; private final String fieldName; private final UiBinderWriter uiWriter; @@ -73,7 +74,7 @@ // that idHolder is a local variable reference, not a string id. We // have to generate the ids at runtime, not compile time, or else // we'll reuse ids for any template rendered more than once. - String idHolder = uiWriter.declareDomIdHolder(); + String idHolder = uiWriter.declareDomIdHolder(fieldName + "_child" + (serial++)); String childField = uiWriter.parseElementToField(elem); uiWriter.ensureFieldAttached(fieldName); Index: user/src/com/google/gwt/uibinder/parsers/WidgetPlaceholderInterpreter.java =================================================================== --- user/src/com/google/gwt/uibinder/parsers/WidgetPlaceholderInterpreter.java (revision 6341) +++ user/src/com/google/gwt/uibinder/parsers/WidgetPlaceholderInterpreter.java (working copy) @@ -90,7 +90,7 @@ name = "widget" + (++serial); } - String idHolder = uiWriter.declareDomIdHolder(); + String idHolder = uiWriter.declareDomIdHolder(name); idToWidgetElement.put(idHolder, elem); if (oracle.findType(HasHTML.class.getName()).isAssignableFrom(type)) { Index: user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java =================================================================== --- user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java (revision 6341) +++ user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java (working copy) @@ -72,8 +72,6 @@ private static final String BUNDLE_URI_SCHEME = "urn:with:"; private static final String PACKAGE_URI_SCHEME = "urn:import:"; - private static int domId = 0; - // TODO(rjrjr) Another place that we need a general anonymous field // mechanism private static final String CLIENT_BUNDLE_FIELD = "clientBundleFieldNameUnlikelyToCollideWithUserSpecifiedFieldOkay"; @@ -339,7 +337,7 @@ public String declareDomField(String fieldName, String parentElementExpression) throws UnableToCompleteException { ensureAttached(parentElementExpression); - String name = declareDomIdHolder(); + String name = declareDomIdHolder(fieldName); setFieldInitializer(fieldName, "null"); addInitStatement( "%s = com.google.gwt.dom.client.Document.get().getElementById(%s).cast();", @@ -354,8 +352,8 @@ * * @return that variable's name. */ - public String declareDomIdHolder() throws UnableToCompleteException { - String domHolderName = "domId" + domId++; + public String declareDomIdHolder(String fieldName) throws UnableToCompleteException { + String domHolderName = "__gwt_domId_" + fieldName; FieldWriter domField = fieldManager.registerField( oracle.findType(String.class.getName()), domHolderName); domField.setInitializer("com.google.gwt.dom.client.Document.get().createUniqueId()"); --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
