diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2014-07-10 16:26:01 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-07-10 16:05:59 +0000 |
commit | 5c931588582025e983ef457b503a1d3c2e6d41b2 (patch) | |
tree | 121b76870b2908c3f0b6deeec724797fa48b540a | |
parent | f27a00b7b9a487a66dd23a4d28aa56fe60a1ad4e (diff) | |
download | vaadin-framework-5c931588582025e983ef457b503a1d3c2e6d41b2.tar.gz vaadin-framework-5c931588582025e983ef457b503a1d3c2e6d41b2.zip |
Generate type data for AbstractRendererConnector.createRenderer (#13334)
The declared return type of the most-derived getRenderer method is stored
to make the default createRenderer implementation work. This is identical
to the way AbstractComponentConnector getWidget and createWidget work.
Change-Id: I879e9e6739e366bd81773a1e65195336e0cdac6d
7 files changed, 79 insertions, 16 deletions
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java index 5519dd1aae..e02317be78 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -61,6 +61,7 @@ import com.vaadin.server.widgetsetutils.metadata.ConnectorInitVisitor; import com.vaadin.server.widgetsetutils.metadata.GeneratedSerializer; import com.vaadin.server.widgetsetutils.metadata.OnStateChangeVisitor; import com.vaadin.server.widgetsetutils.metadata.Property; +import com.vaadin.server.widgetsetutils.metadata.RendererInitVisitor; import com.vaadin.server.widgetsetutils.metadata.ServerRpcVisitor; import com.vaadin.server.widgetsetutils.metadata.StateInitVisitor; import com.vaadin.server.widgetsetutils.metadata.TypeVisitor; @@ -1235,8 +1236,9 @@ public class ConnectorBundleLoaderFactory extends Generator { throws NotFoundException { List<TypeVisitor> visitors = Arrays.<TypeVisitor> asList( new ConnectorInitVisitor(), new StateInitVisitor(), - new WidgetInitVisitor(), new ClientRpcVisitor(), - new ServerRpcVisitor(), new OnStateChangeVisitor()); + new WidgetInitVisitor(), new RendererInitVisitor(), + new ClientRpcVisitor(), new ServerRpcVisitor(), + new OnStateChangeVisitor()); for (TypeVisitor typeVisitor : visitors) { typeVisitor.init(oracle); } diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java index 8bbcac4ecb..463bf00027 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java @@ -43,6 +43,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.communication.JSONSerializer; import com.vaadin.client.ui.UnknownComponentConnector; +import com.vaadin.client.ui.grid.renderers.AbstractRendererConnector; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.ui.Connect; @@ -414,6 +415,11 @@ public class ConnectorBundle { return isConnected(type) && isType(type, ComponentConnector.class); } + public static boolean isConnectedRendererConnector(JClassType type) { + return isConnected(type) + && isType(type, AbstractRendererConnector.class); + } + private static boolean isInterfaceType(JClassType type, Class<?> class1) { return type.isInterface() != null && isType(type, class1); } diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererInitVisitor.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererInitVisitor.java new file mode 100644 index 0000000000..ec68f05b8f --- /dev/null +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererInitVisitor.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * 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.vaadin.server.widgetsetutils.metadata; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.core.ext.typeinfo.JClassType; +import com.google.gwt.core.ext.typeinfo.JMethod; +import com.vaadin.client.ui.grid.renderers.AbstractRendererConnector; + +/** + * Generates type data for renderer connectors. Specifically, stores the return + * type of the overridden {@link AbstractRendererConnector#getRenderer() + * getRenderer} method to enable automatic creation of an instance of the proper + * renderer type. + * + * @see WidgetInitVisitor + * + * @since + * @author Vaadin Ltd + */ +public class RendererInitVisitor extends TypeVisitor { + + @Override + public void visitConnector(TreeLogger logger, JClassType type, + ConnectorBundle bundle) throws UnableToCompleteException { + + if (ConnectorBundle.isConnectedRendererConnector(type)) { + + // The class in which createRenderer is implemented + JClassType createRendererClass = ConnectorBundle + .findInheritedMethod(type, "createRenderer") + .getEnclosingType(); + + JMethod getRenderer = ConnectorBundle.findInheritedMethod(type, + "getRenderer"); + JClassType rendererType = getRenderer.getReturnType().isClass(); + + // Needs GWT constructor if createRenderer is not overridden + if (createRendererClass.getQualifiedSourceName().equals( + AbstractRendererConnector.class.getCanonicalName())) { + + bundle.setNeedsGwtConstructor(rendererType); + + // Also needs renderer type to find the right GWT constructor + bundle.setNeedsReturnType(type, getRenderer); + } + } + } +} diff --git a/client/src/com/vaadin/client/ui/grid/renderers/TextRendererConnector.java b/client/src/com/vaadin/client/ui/grid/renderers/TextRendererConnector.java index 18cc84cd34..84b261415b 100644 --- a/client/src/com/vaadin/client/ui/grid/renderers/TextRendererConnector.java +++ b/client/src/com/vaadin/client/ui/grid/renderers/TextRendererConnector.java @@ -32,11 +32,6 @@ public class TextRendererConnector extends AbstractRendererConnector<String> { } @Override - public TextRenderer createRenderer() { - return new TextRenderer(); - } - - @Override public Class<String> getType() { return String.class; } diff --git a/client/src/com/vaadin/client/ui/grid/renderers/UnsafeHtmlRendererConnector.java b/client/src/com/vaadin/client/ui/grid/renderers/UnsafeHtmlRendererConnector.java index 1816ac974a..7d5b9e1c60 100644 --- a/client/src/com/vaadin/client/ui/grid/renderers/UnsafeHtmlRendererConnector.java +++ b/client/src/com/vaadin/client/ui/grid/renderers/UnsafeHtmlRendererConnector.java @@ -29,7 +29,7 @@ import com.vaadin.shared.ui.Connect; public class UnsafeHtmlRendererConnector extends AbstractRendererConnector<String> { - public class UnsafeHtmlRenderer implements Renderer<String> { + public static class UnsafeHtmlRenderer implements Renderer<String> { @Override public void render(FlyweightCell cell, String data) { cell.getElement().setInnerHTML(data); @@ -42,11 +42,6 @@ public class UnsafeHtmlRendererConnector extends } @Override - protected UnsafeHtmlRenderer createRenderer() { - return new UnsafeHtmlRenderer(); - } - - @Override public Class<String> getType() { return String.class; } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java index be358c2738..dc424e7606 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java @@ -23,7 +23,7 @@ import com.vaadin.shared.ui.Connect; @Connect(com.vaadin.tests.components.grid.IntArrayRenderer.class) public class IntArrayRendererConnector extends AbstractRendererConnector<int[]> { - public class IntArrayRenderer implements Renderer<int[]> { + public static class IntArrayRenderer implements Renderer<int[]> { private static final String JOINER = " :: "; @Override @@ -40,8 +40,8 @@ public class IntArrayRendererConnector extends AbstractRendererConnector<int[]> } @Override - protected IntArrayRenderer createRenderer() { - return new IntArrayRenderer(); + public IntArrayRenderer getRenderer() { + return (IntArrayRenderer) super.getRenderer(); } @Override diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java index c82c6c9a18..40dbbeb370 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java @@ -73,6 +73,8 @@ public class RowAwareRendererConnector extends AbstractRendererConnector<Void> { @Override protected Renderer<Void> createRenderer() { + // cannot use the default createRenderer as RowAwareRenderer needs a + // reference to its connector - it has no "real" no-argument constructor return new RowAwareRenderer(); } } |