Fixed name clash in uibinder when a field is named "owner"
bug: issue 7327
Change-Id: Id9e1a77433a09e913e8ef045c63b3f5bff4bbf17
diff --git a/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java b/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
index a98a249..6ac628b 100644
--- a/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
+++ b/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
@@ -335,7 +335,7 @@
if ((ownerField != null) && !ownerField.isProvided()) {
w.newline();
- w.write("owner.%1$s = %1$s;", name);
+ w.write("this.owner.%1$s = %1$s;", name);
}
w.newline();
diff --git a/user/test/com/google/gwt/uibinder/test/client/UiBinderNameConflictsTest.Ui.ui.xml b/user/test/com/google/gwt/uibinder/test/client/UiBinderNameConflictsTest.Ui.ui.xml
new file mode 100644
index 0000000..c51b0fc
--- /dev/null
+++ b/user/test/com/google/gwt/uibinder/test/client/UiBinderNameConflictsTest.Ui.ui.xml
@@ -0,0 +1,21 @@
+<!-- -->
+<!-- Copyright 2013 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 -->
+<!-- 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. License for the specific language governing permissions and -->
+<!-- limitations under the License. -->
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:g='urn:import:com.google.gwt.user.client.ui'
+ >
+ <g:HTMLPanel>
+ <g:Button ui:field="template" text="templateBtn"/>
+ <g:Button ui:field="owner" text="ownerBtn"/>
+ </g:HTMLPanel>
+</ui:UiBinder>
diff --git a/user/test/com/google/gwt/uibinder/test/client/UiBinderNameConflictsTest.java b/user/test/com/google/gwt/uibinder/test/client/UiBinderNameConflictsTest.java
new file mode 100644
index 0000000..28cc7c4
--- /dev/null
+++ b/user/test/com/google/gwt/uibinder/test/client/UiBinderNameConflictsTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2013 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
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.uibinder.test.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HTMLPanel;
+
+/**
+ * Integration tests covering potential name conflicts in {@link UiBinder}.
+ */
+public class UiBinderNameConflictsTest extends GWTTestCase {
+
+ static class Ui extends Composite {
+ interface Binder extends UiBinder<HTMLPanel, Ui> {
+ }
+
+ @UiField Button template;
+ @UiField Button owner;
+ }
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.uibinder.test.UiBinderSuite";
+ }
+
+ public void testNameConflicts() {
+ Ui.Binder binder = GWT.create(Ui.Binder.class);
+ Ui subject = new Ui();
+ binder.createAndBindUi(subject);
+
+ assertEquals("templateBtn", subject.template.getText());
+ assertEquals("ownerBtn", subject.owner.getText());
+ }
+}