Keeps LazyPanelParser from breaking existing templates that use
@UiField(provided = true) to get LazyPanels into templates.

Review at http://gwt-code-reviews.appspot.com/1577804

Review by: rchandia@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10719 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/uibinder/elementparsers/LazyPanelParser.java b/user/src/com/google/gwt/uibinder/elementparsers/LazyPanelParser.java
index 886f601..4d24cbf 100644
--- a/user/src/com/google/gwt/uibinder/elementparsers/LazyPanelParser.java
+++ b/user/src/com/google/gwt/uibinder/elementparsers/LazyPanelParser.java
@@ -37,6 +37,10 @@
   public void parse(XMLElement elem, String fieldName, JClassType type,
       UiBinderWriter writer) throws UnableToCompleteException {
 
+    if (writer.getOwnerClass().getUiField(fieldName).isProvided()) {
+      return;
+    }
+
     if (!writer.useLazyWidgetBuilders()) {
       writer.die("LazyPanel only works with UiBinder.useLazyWidgetBuilders enabled.");
     }
diff --git a/user/test/com/google/gwt/uibinder/LazyWidgetBuilderSuite.java b/user/test/com/google/gwt/uibinder/LazyWidgetBuilderSuite.java
index d237d85..0a339b8 100644
--- a/user/test/com/google/gwt/uibinder/LazyWidgetBuilderSuite.java
+++ b/user/test/com/google/gwt/uibinder/LazyWidgetBuilderSuite.java
@@ -18,11 +18,12 @@
 import com.google.gwt.junit.tools.GWTTestSuite;
 import com.google.gwt.uibinder.test.client.CellPanelParserIntegrationTest;
 import com.google.gwt.uibinder.test.client.IsRenderableIntegrationTest;
+import com.google.gwt.uibinder.test.client.LazyPanelParserIntegrationTest;
 import com.google.gwt.uibinder.test.client.LazyWidgetBuilderSafeUriIntegrationTest;
 import com.google.gwt.uibinder.test.client.SafeHtmlAsComponentsTest;
 import com.google.gwt.uibinder.test.client.UiBinderParserUiWithAttributesTest;
-import com.google.gwt.uibinder.test.client.UiRendererTest;
 import com.google.gwt.uibinder.test.client.UiRendererEventsTest;
+import com.google.gwt.uibinder.test.client.UiRendererTest;
 
 import junit.framework.Test;
 
@@ -36,6 +37,7 @@
 
     suite.addTestSuite(CellPanelParserIntegrationTest.class);
     suite.addTestSuite(IsRenderableIntegrationTest.class);
+    suite.addTestSuite(LazyPanelParserIntegrationTest.class);
     suite.addTestSuite(LazyWidgetBuilderSafeUriIntegrationTest.class);
     suite.addTestSuite(SafeHtmlAsComponentsTest.class);
     suite.addTestSuite(UiBinderParserUiWithAttributesTest.class);
diff --git a/user/test/com/google/gwt/uibinder/test/client/CellPanelParserIntegrationTest.java b/user/test/com/google/gwt/uibinder/test/client/CellPanelParserIntegrationTest.java
index a40119f..0f617d6 100644
--- a/user/test/com/google/gwt/uibinder/test/client/CellPanelParserIntegrationTest.java
+++ b/user/test/com/google/gwt/uibinder/test/client/CellPanelParserIntegrationTest.java
@@ -16,15 +16,16 @@
 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.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.Widget;
 
 /**
- * Tests SafeUri parsing with the lazy widget builder.
+ * Integration test for CellPanelParser parsing with the lazy widget builder.
  */
-public class CellPanelParserIntegrationTest extends SafeUriIntegrationTest {
+public class CellPanelParserIntegrationTest extends GWTTestCase {
   static class Renderable extends Composite {
     interface Binder extends UiBinder<Widget, Renderable> {
     }
diff --git a/user/test/com/google/gwt/uibinder/test/client/LazyPanelParserIntegrationTest.Renderable.ui.xml b/user/test/com/google/gwt/uibinder/test/client/LazyPanelParserIntegrationTest.Renderable.ui.xml
new file mode 100644
index 0000000..2e953f7
--- /dev/null
+++ b/user/test/com/google/gwt/uibinder/test/client/LazyPanelParserIntegrationTest.Renderable.ui.xml
@@ -0,0 +1,29 @@
+<!--
+  Copyright 2011 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:gwt='urn:import:com.google.gwt.user.client.ui'>
+  <gwt:VerticalPanel ui:field='verticalPanel'>
+    <gwt:cell horizontalAlignment='ALIGN_RIGHT'>
+      <gwt:HTMLPanel>
+        <gwt:LazyPanel ui:field="generated">
+          <gwt:Anchor text='Refresh' ui:field='refresh'
+            href='javascript:void(0)' />
+        </gwt:LazyPanel>
+        |
+        <gwt:LazyPanel ui:field="provided"/>
+      </gwt:HTMLPanel>
+    </gwt:cell>
+  </gwt:VerticalPanel>
+</ui:UiBinder>
diff --git a/user/test/com/google/gwt/uibinder/test/client/LazyPanelParserIntegrationTest.java b/user/test/com/google/gwt/uibinder/test/client/LazyPanelParserIntegrationTest.java
new file mode 100644
index 0000000..c888c1d
--- /dev/null
+++ b/user/test/com/google/gwt/uibinder/test/client/LazyPanelParserIntegrationTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2011 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.Composite;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.LazyPanel;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * Tests SafeUri parsing with the lazy widget builder.
+ */
+public class LazyPanelParserIntegrationTest extends GWTTestCase {
+  static class Renderable extends Composite {
+    interface Binder extends UiBinder<Widget, Renderable> {
+    }
+
+    private static final Binder BINDER = GWT.create(Binder.class);
+
+    @UiField LazyPanel generated;
+    final @UiField(provided = true) LazyPanel provided = new LazyPanel() {
+      @Override
+      protected Widget createWidget() {
+        return new Label();
+      }
+    };
+
+    public Renderable() {
+      initWidget(BINDER.createAndBindUi(this));
+    }
+  }
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.uibinder.test.LazyWidgetBuilderSuite";
+  }
+
+  public void testIsRenderable() {
+    Renderable ui = new Renderable();
+
+    try {
+      RootPanel.get().add(ui);
+    } finally {
+      ui.removeFromParent();
+    }
+  }
+
+}