diff options
author | Leif Åstrand <leif@vaadin.com> | 2014-03-05 16:07:10 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-03-11 06:46:31 +0000 |
commit | 4e5d14e1e2e90c0be9f4a5b1dfb40d55d7620ce2 (patch) | |
tree | 64ad023af0cb52896a86c74cc433c83c7c84f3f0 | |
parent | 9f073198fe60a5e92d279e26a441aa47a3bf075d (diff) | |
download | vaadin-framework-4e5d14e1e2e90c0be9f4a5b1dfb40d55d7620ce2.tar.gz vaadin-framework-4e5d14e1e2e90c0be9f4a5b1dfb40d55d7620ce2.zip |
Ignore type parameters when looking for metadata (#12873, #12900)
All code populating the TypeDataStore is generated using
writeClassLiteral which strips away all type parameters, so the code
doing lookups should also do the same to maintain compatibility.
Change-Id: I01654f4cc15188a12c735ffed55d30a34c77a064
9 files changed, 243 insertions, 29 deletions
diff --git a/client/src/com/vaadin/client/metadata/Method.java b/client/src/com/vaadin/client/metadata/Method.java index aea2fd7f85..390574cdf8 100644 --- a/client/src/com/vaadin/client/metadata/Method.java +++ b/client/src/com/vaadin/client/metadata/Method.java @@ -19,13 +19,10 @@ public class Method { private final Type type; private final String name; - private String signature; public Method(Type type, String name) { this.type = type; this.name = name; - // Cache derived signature value - signature = type.getSignature() + "." + name; } public Type getType() { @@ -53,7 +50,20 @@ public class Method { * @return the unique signature of this method */ public String getSignature() { - return signature; + return type.getSignature() + "." + name; + } + + /** + * Gets the string that is internally used when looking up generated support + * code for this method. This is the same as {@link #getSignature()}, but + * without any type parameters. + * + * @return the string to use for looking up generated support code + * + * @since 7.2 + */ + public String getLookupKey() { + return type.getBaseTypeName() + "." + name; } @Override diff --git a/client/src/com/vaadin/client/metadata/Property.java b/client/src/com/vaadin/client/metadata/Property.java index 64fbb79ca1..72ed7fec41 100644 --- a/client/src/com/vaadin/client/metadata/Property.java +++ b/client/src/com/vaadin/client/metadata/Property.java @@ -20,13 +20,10 @@ import com.vaadin.shared.annotations.DelegateToWidget; public class Property { private final Type bean; private final String name; - private final String signature; public Property(Type bean, String name) { this.bean = bean; this.name = name; - // Cache derived signature value - signature = bean.getSignature() + "." + name; } public Object getValue(Object bean) throws NoDataException { @@ -63,7 +60,20 @@ public class Property { * @return the unique signature of this property */ public String getSignature() { - return signature; + return bean.getSignature() + "." + name; + } + + /** + * Gets the string that is internally used when looking up generated support + * code for this method. This is the same as {@link #getSignature()}, but + * without any type parameters. + * + * @return the string to use for looking up generated support code + * + * @since 7.2 + */ + public String getLookupKey() { + return bean.getBaseTypeName() + "." + name; } @Override diff --git a/client/src/com/vaadin/client/metadata/TypeDataStore.java b/client/src/com/vaadin/client/metadata/TypeDataStore.java index a3939b7994..d5fbc94823 100644 --- a/client/src/com/vaadin/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/client/metadata/TypeDataStore.java @@ -87,7 +87,7 @@ public class TypeDataStore { } public static Type getReturnType(Method method) throws NoDataException { - Type type = get().returnTypes.get(method.getSignature()); + Type type = get().returnTypes.get(method.getLookupKey()); if (type == null) { throw new NoDataException("There is no return type for " + method.getSignature()); @@ -96,7 +96,7 @@ public class TypeDataStore { } public static Invoker getInvoker(Method method) throws NoDataException { - Invoker invoker = get().invokers.get(method.getSignature()); + Invoker invoker = get().invokers.get(method.getLookupKey()); if (invoker == null) { throw new NoDataException("There is no invoker for " + method.getSignature()); @@ -106,7 +106,7 @@ public class TypeDataStore { public static Invoker getConstructor(Type type) throws NoDataException { Invoker invoker = get().invokers.get(new Method(type, CONSTRUCTOR_NAME) - .getSignature()); + .getLookupKey()); if (invoker == null) { throw new NoDataException("There is no constructor for " + type.getSignature()); @@ -121,29 +121,30 @@ public class TypeDataStore { } public static String getDelegateToWidget(Property property) { - return get().delegateToWidget.get(property.getSignature()); + return get().delegateToWidget.get(property.getLookupKey()); } public static JsArrayString getDelegateToWidgetProperites(Type type) { - return get().delegateToWidgetProperties.get(type.getSignature()); + return get().delegateToWidgetProperties.get(type.getBaseTypeName()); } public void setDelegateToWidget(Class<?> clazz, String propertyName, String delegateValue) { Type type = getType(clazz); - delegateToWidget.put(new Property(type, propertyName).getSignature(), + delegateToWidget.put(new Property(type, propertyName).getLookupKey(), delegateValue); JsArrayString typeProperties = delegateToWidgetProperties.get(type - .getSignature()); + .getBaseTypeName()); if (typeProperties == null) { typeProperties = JavaScriptObject.createArray().cast(); - delegateToWidgetProperties.put(type.getSignature(), typeProperties); + delegateToWidgetProperties.put(type.getBaseTypeName(), + typeProperties); } typeProperties.push(propertyName); } public void setReturnType(Class<?> type, String methodName, Type returnType) { - returnTypes.put(new Method(getType(type), methodName).getSignature(), + returnTypes.put(new Method(getType(type), methodName).getLookupKey(), returnType); } @@ -152,12 +153,12 @@ public class TypeDataStore { } public void setInvoker(Class<?> type, String methodName, Invoker invoker) { - invokers.put(new Method(getType(type), methodName).getSignature(), + invokers.put(new Method(getType(type), methodName).getLookupKey(), invoker); } public static Type[] getParamTypes(Method method) throws NoDataException { - Type[] types = get().paramTypes.get(method.getSignature()); + Type[] types = get().paramTypes.get(method.getLookupKey()); if (types == null) { throw new NoDataException("There are no parameter type data for " + method.getSignature()); @@ -168,7 +169,7 @@ public class TypeDataStore { public void setParamTypes(Class<?> type, String methodName, Type[] paramTypes) { this.paramTypes.put( - new Method(getType(type), methodName).getSignature(), + new Method(getType(type), methodName).getLookupKey(), paramTypes); } @@ -178,8 +179,8 @@ public class TypeDataStore { public static ProxyHandler getProxyHandler(Type type) throws NoDataException { - ProxyHandler proxyHandler = get().proxyHandlers - .get(type.getSignature()); + ProxyHandler proxyHandler = get().proxyHandlers.get(type + .getBaseTypeName()); if (proxyHandler == null) { throw new NoDataException("No proxy handler for " + type.getSignature()); @@ -188,24 +189,24 @@ public class TypeDataStore { } public void setProxyHandler(Class<?> type, ProxyHandler proxyHandler) { - proxyHandlers.put(getType(type).getSignature(), proxyHandler); + proxyHandlers.put(getType(type).getBaseTypeName(), proxyHandler); } public static boolean isDelayed(Method method) { - return get().delayedMethods.contains(method.getSignature()); + return get().delayedMethods.contains(method.getLookupKey()); } public void setDelayed(Class<?> type, String methodName) { - delayedMethods.add(getType(type).getMethod(methodName).getSignature()); + delayedMethods.add(getType(type).getMethod(methodName).getLookupKey()); } public static boolean isLastOnly(Method method) { - return get().lastOnlyMethods.contains(method.getSignature()); + return get().lastOnlyMethods.contains(method.getLookupKey()); } public void setLastOnly(Class<?> clazz, String methodName) { lastOnlyMethods - .add(getType(clazz).getMethod(methodName).getSignature()); + .add(getType(clazz).getMethod(methodName).getLookupKey()); } /** @@ -259,12 +260,12 @@ public class TypeDataStore { } public void setSerializerFactory(Class<?> clazz, Invoker factory) { - serializerFactories.put(getType(clazz).getSignature(), factory); + serializerFactories.put(getType(clazz).getBaseTypeName(), factory); } public static JSONSerializer<?> findSerializer(Type type) { Invoker factoryCreator = get().serializerFactories.get(type - .getSignature()); + .getBaseTypeName()); if (factoryCreator == null) { return null; } diff --git a/uitest/src/com/vaadin/tests/serialization/GenericWidgetHandling.java b/uitest/src/com/vaadin/tests/serialization/GenericWidgetHandling.java new file mode 100644 index 0000000000..dca96a46ea --- /dev/null +++ b/uitest/src/com/vaadin/tests/serialization/GenericWidgetHandling.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2013 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.tests.serialization; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.server.GenericWidgetComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class GenericWidgetHandling extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final GenericWidgetComponent component = new GenericWidgetComponent(); + component.setId("label"); + component.setGenericText("The generic text is strong in this one"); + addComponent(component); + } + + @Override + protected String getTestDescription() { + return "Tests that a connector works even if its widget is of a generic type"; + } + + @Override + protected Integer getTicketNumber() { + // Also 12900 if someone happens to care + return Integer.valueOf(12873); + } + +} diff --git a/uitest/src/com/vaadin/tests/serialization/GenericWidgetHandlingTest.java b/uitest/src/com/vaadin/tests/serialization/GenericWidgetHandlingTest.java new file mode 100644 index 0000000000..a6ff0c4459 --- /dev/null +++ b/uitest/src/com/vaadin/tests/serialization/GenericWidgetHandlingTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2013 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.tests.serialization; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GenericWidgetHandlingTest extends MultiBrowserTest { + + @Test + public void testWidgetInit() { + openTestURL(); + WebElement label = vaadinElementById("label"); + + Assert.assertEquals("The generic text is strong in this one", + label.getText()); + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/GenericWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/GenericWidget.java new file mode 100644 index 0000000000..bf191d1e87 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/GenericWidget.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2013 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.tests.widgetset.client; + +import com.google.gwt.user.client.ui.Label; + +public class GenericWidget<T> extends Label { + public void setGenericText(T value) { + setText(String.valueOf(value)); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/GenericWidgetConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/GenericWidgetConnector.java new file mode 100644 index 0000000000..a05bedfa27 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/GenericWidgetConnector.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2013 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.tests.widgetset.client; + +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.GenericWidgetComponent; + +@Connect(GenericWidgetComponent.class) +public class GenericWidgetConnector extends AbstractComponentConnector { + @Override + public GenericWidget<String> getWidget() { + return (GenericWidget<String>) super.getWidget(); + } + + @Override + public GenericWidgetState getState() { + return (GenericWidgetState) super.getState(); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/GenericWidgetState.java b/uitest/src/com/vaadin/tests/widgetset/client/GenericWidgetState.java new file mode 100644 index 0000000000..79dce8de9f --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/GenericWidgetState.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2013 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.tests.widgetset.client; + +import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; + +public class GenericWidgetState extends AbstractComponentState { + @DelegateToWidget + public String genericText; +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/GenericWidgetComponent.java b/uitest/src/com/vaadin/tests/widgetset/server/GenericWidgetComponent.java new file mode 100644 index 0000000000..2be59ee96b --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/GenericWidgetComponent.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2013 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.tests.widgetset.server; + +import com.vaadin.tests.widgetset.client.GenericWidgetState; +import com.vaadin.ui.AbstractComponent; + +public class GenericWidgetComponent extends AbstractComponent { + + @Override + protected GenericWidgetState getState() { + return (GenericWidgetState) super.getState(); + } + + public void setGenericText(String genericText) { + getState().genericText = genericText; + } +} |