]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support long in state again (#13692)
authorJonatan Kronqvist <jonatan@vaadin.com>
Sun, 11 May 2014 09:38:08 +0000 (12:38 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 12 May 2014 12:05:18 +0000 (12:05 +0000)
The fix to #9379 broke the support for long type fields in state classes. This
patch bypasses the unboxing of long values and adds the @UnsafeNativeLong annotation
to the methods which may fetch and return (without modifying) long values.

SerializerTest is extended to test the different data types in States.

Change-Id: I29fd2c6af13cd9a0d29ecb1444ed9eb8a2b013e3

client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java
uitest/src/com/vaadin/tests/serialization/SerializerTest.java
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestConnector.java
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestRpc.java
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestState.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/server/SerializerTestExtension.java

index 75225c52dcdafc4014332d5f1748be6a29f4502d..cc1841ec05c45de151aec6028b74ef658e61a544 100644 (file)
@@ -189,6 +189,8 @@ public class ConnectorBundleLoaderFactory extends Generator {
                 if (isNative) {
                     outdent();
                     println("}-*/;");
+                    // To support fields of type long (#13692)
+                    println("@com.google.gwt.core.client.UnsafeNativeLong");
                     println("private native void %s(%s) /*-{", newMethod, args);
                 } else {
                     println("%s();", newMethod);
@@ -313,6 +315,8 @@ public class ConnectorBundleLoaderFactory extends Generator {
 
             // Separate method for loading native JS stuff (e.g. callbacks)
             String loadNativeJsMethodName = "loadNativeJs";
+            // To support fields of type long (#13692)
+            w.println("@com.google.gwt.core.client.UnsafeNativeLong");
             w.println("private native void %s(%s store) /*-{",
                     loadNativeJsMethodName, TypeDataStore.class.getName());
             w.indent();
index a31dafe05ca2d0e14d88b3fc2bdd468a0c92d51c..6c242dfd741737607c2317c94ed2105ba0be7f31 100644 (file)
@@ -45,17 +45,25 @@ public class FieldProperty extends Property {
     @Override
     public void writeSetterBody(TreeLogger logger, SourceWriter w,
             String beanVariable, String valueVariable) {
+        // Don't try to unbox Longs in javascript, as it's not supported.
+        // (#13692)
+        boolean shouldUnbox = !"long".equals(field.getType()
+                .getSimpleSourceName());
         w.println("%s.@%s::%s = %s;", beanVariable, getBeanType()
-                .getQualifiedSourceName(), getName(), unboxValue(valueVariable));
+                .getQualifiedSourceName(), getName(),
+                shouldUnbox ? unboxValue(valueVariable) : valueVariable);
     }
 
     @Override
     public void writeGetterBody(TreeLogger logger, SourceWriter w,
             String beanVariable) {
+        // Longs are not unboxed, as it's not supported. (#13692)
+        boolean shouldBox = !"long".equals(field.getType()
+                .getSimpleSourceName());
         String value = String.format("%s.@%s::%s", beanVariable, getBeanType()
                 .getQualifiedSourceName(), getName());
         w.print("return ");
-        w.print(boxValue(value));
+        w.print(shouldBox ? boxValue(value) : value);
         w.println(";");
     }
 
index 990b350c97877c7d43a5e7b21496770959c2b326..1c18fb1912d15b23e6d1b451e8cd81f3f5ec3240 100644 (file)
@@ -38,6 +38,7 @@ import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.tests.util.Log;
 import com.vaadin.tests.widgetset.client.ComplexTestBean;
 import com.vaadin.tests.widgetset.client.SerializerTestRpc;
+import com.vaadin.tests.widgetset.client.SerializerTestState;
 import com.vaadin.tests.widgetset.client.SimpleTestBean;
 import com.vaadin.tests.widgetset.server.SerializerTestExtension;
 
@@ -58,44 +59,110 @@ public class SerializerTest extends AbstractTestUI {
 
         SerializerTestRpc rpc = testExtension
                 .getRpcProxy(SerializerTestRpc.class);
+        SerializerTestState state = testExtension.getState();
+
         rpc.sendBeanSubclass(new SimpleTestBean() {
             @Override
             public int getValue() {
                 return 42;
             }
         });
+        state.simpleTestBean = new SimpleTestBean() {
+            @Override
+            public int getValue() {
+                return 42;
+            }
+        };
+
         rpc.sendBoolean(true, Boolean.FALSE, new boolean[] { true, true, false,
                 true, false, false });
+        state.booleanValue = true;
+        state.booleanObjectValue = Boolean.FALSE;
+        state.booleanArray = new boolean[] { true, true, false, true, false,
+                false };
+
         rpc.sendByte((byte) 5, Byte.valueOf((byte) -12), new byte[] { 3, 1, 2 });
+        state.byteValue = (byte) 5;
+        state.byteObjectValue = Byte.valueOf((byte) -12);
+        state.byteArray = new byte[] { 3, 1, 2 };
+
         rpc.sendChar('\u222b', Character.valueOf('å'), "aBcD".toCharArray());
+        state.charValue = '\u222b';
+        state.charObjectValue = Character.valueOf('å');
+        state.charArray = "aBcD".toCharArray();
+
         rpc.sendInt(Integer.MAX_VALUE, Integer.valueOf(0), new int[] { 5, 7 });
+        state.intValue = Integer.MAX_VALUE;
+        state.intObjectValue = Integer.valueOf(0);
+        state.intArray = new int[] { 5, 7 };
+
         rpc.sendLong(577431841358l, Long.valueOf(0), new long[] {
                 -57841235865l, 57 });
+        state.longValue = 577431841358l;
+        state.longObjectValue = Long.valueOf(0);
+        state.longArray = new long[] { -57841235865l, 57 };
+
         rpc.sendFloat(3.14159f, Float.valueOf(Math.nextUp(1)), new float[] {
                 57, 0, -12 });
+        state.floatValue = 3.14159f;
+        state.floatObjectValue = Float.valueOf(Math.nextUp(1));
+        state.floatArray = new float[] { 57, 0, -12 };
+
         rpc.sendDouble(Math.PI, Double.valueOf(-Math.E), new double[] {
                 Double.MAX_VALUE, Double.MIN_VALUE });
+        state.doubleValue = Math.PI;
+        state.doubleValue = Double.valueOf(-Math.E);
+        state.doubleArray = new double[] { Double.MAX_VALUE, Double.MIN_VALUE };
+
         rpc.sendString("This is a tesing string ‡");
+        state.string = "This is a tesing string ‡";
+
         rpc.sendConnector(this);
+        state.connector = this;
+
         rpc.sendBean(
                 new ComplexTestBean(new SimpleTestBean(0),
                         new SimpleTestBean(1), Arrays.asList(
                                 new SimpleTestBean(3), new SimpleTestBean(4)),
                         5), new SimpleTestBean(6),
                 new SimpleTestBean[] { new SimpleTestBean(7) });
+        state.complexTestBean = new ComplexTestBean(new SimpleTestBean(0),
+                new SimpleTestBean(1), Arrays.asList(new SimpleTestBean(3),
+                        new SimpleTestBean(4)), 5);
+        state.simpleTestBean = new SimpleTestBean(6);
+        state.simpleTestBeanArray = new SimpleTestBean[] { new SimpleTestBean(7) };
+
         rpc.sendNull("Not null", null);
+        state.nullString = null;
+
         rpc.sendNestedArray(new int[][] { { 5 }, { 7 } },
                 new SimpleTestBean[][] { { new SimpleTestBean(4),
                         new SimpleTestBean(2) } });
+        state.nestedIntArray = new int[][] { { 5 }, { 7 } };
+        state.nestedBeanArray = new SimpleTestBean[][] { {
+                new SimpleTestBean(4), new SimpleTestBean(2) } };
+
         rpc.sendList(Arrays.asList(5, 8, -234), Arrays.<Connector> asList(this,
                 testExtension), Arrays.asList(new SimpleTestBean(234),
                 new SimpleTestBean(-568)));
+        state.intList = Arrays.asList(5, 8, -234);
+        state.connectorList = Arrays.<Connector> asList(this, testExtension);
+        state.simpleTestBeanList = Arrays.asList(new SimpleTestBean(234),
+                new SimpleTestBean(-568));
+
         rpc.sendArrayList(
                 Arrays.asList(new int[] { 1, 2 }, new int[] { 3, 4 }),
                 Arrays.asList(new Integer[] { 5, 6 }, new Integer[] { 7, 8 }),
                 Collections
                         .singletonList(new SimpleTestBean[] { new SimpleTestBean(
                                 7) }));
+        state.primitiveArrayList = Arrays.asList(new int[] { 1, 2 }, new int[] {
+                3, 4 });
+        state.objectArrayList = Arrays.asList(new Integer[] { 5, 6 },
+                new Integer[] { 7, 8 });
+        state.beanArrayList = Collections
+                .singletonList(new SimpleTestBean[] { new SimpleTestBean(7) });
+
         // Disabled because of #8861
         // rpc.sendListArray(
         // new List[] { Arrays.asList(1, 2), Arrays.asList(3, 4) },
@@ -103,6 +170,11 @@ public class SerializerTest extends AbstractTestUI {
         rpc.sendSet(new HashSet<Integer>(Arrays.asList(4, 7, 12)), Collections
                 .singleton((Connector) this), new HashSet<SimpleTestBean>(
                 Arrays.asList(new SimpleTestBean(1), new SimpleTestBean(2))));
+        state.intSet = new HashSet<Integer>(Arrays.asList(4, 7, 12));
+        state.connectorSet = Collections.singleton((Connector) this);
+
+        state.beanSet = new HashSet<SimpleTestBean>(Arrays.asList(
+                new SimpleTestBean(1), new SimpleTestBean(2)));
 
         rpc.sendMap(new HashMap<String, SimpleTestBean>() {
             {
@@ -125,6 +197,31 @@ public class SerializerTest extends AbstractTestUI {
                 put(new SimpleTestBean(-4), new SimpleTestBean(4));
             }
         });
+        state.stringMap = new HashMap<String, SimpleTestBean>() {
+            {
+                put("1", new SimpleTestBean(1));
+                put("2", new SimpleTestBean(2));
+            }
+        };
+        state.connectorMap = new HashMap<Connector, SimpleTestBean>() {
+            {
+                put(testExtension, new SimpleTestBean(3));
+                put(getUI(), new SimpleTestBean(4));
+            }
+        };
+        state.intMap = new HashMap<Integer, Connector>() {
+            {
+                put(5, testExtension);
+                put(10, getUI());
+            }
+        };
+        state.beanMap = new HashMap<SimpleTestBean, SimpleTestBean>() {
+            {
+                put(new SimpleTestBean(5), new SimpleTestBean(-5));
+                put(new SimpleTestBean(-4), new SimpleTestBean(4));
+            }
+        };
+
         rpc.sendWrappedGenerics(new HashMap<Set<SimpleTestBean>, Map<Integer, List<SimpleTestBean>>>() {
             {
                 put(Collections.singleton(new SimpleTestBean(42)),
@@ -136,13 +233,32 @@ public class SerializerTest extends AbstractTestUI {
                         });
             }
         });
+        state.generics = new HashMap<Set<SimpleTestBean>, Map<Integer, List<SimpleTestBean>>>() {
+            {
+                put(Collections.singleton(new SimpleTestBean(42)),
+                        new HashMap<Integer, List<SimpleTestBean>>() {
+                            {
+                                put(1, Arrays.asList(new SimpleTestBean(1),
+                                        new SimpleTestBean(3)));
+                            }
+                        });
+            }
+        };
 
         rpc.sendEnum(ContentMode.TEXT, new ContentMode[] {
                 ContentMode.PREFORMATTED, ContentMode.XML },
                 Arrays.asList(ContentMode.HTML, ContentMode.RAW));
 
+        state.contentMode = ContentMode.TEXT;
+        state.array = new ContentMode[] { ContentMode.PREFORMATTED,
+                ContentMode.XML };
+        state.list = Arrays.asList(ContentMode.HTML, ContentMode.RAW);
+
         rpc.sendDate(new Date(1));
         rpc.sendDate(new Date(2013 - 1900, 5 - 1, 31, 11, 12, 13));
+        state.date1 = new Date(1);
+        state.date2 = new Date(2013 - 1900, 5 - 1, 31, 11, 12, 13);
+
         testExtension.registerRpc(new SerializerTestRpc() {
             @Override
             public void sendBoolean(boolean value, Boolean boxedValue,
@@ -331,6 +447,12 @@ public class SerializerTest extends AbstractTestUI {
                 log.log("sendDate: " + format.format(date));
             }
 
+            @Override
+            public void log(String string) {
+                log.log(string);
+
+            }
+
         });
     }
 
index f1917aaeb9c25fa6cba99cbc056d683473f60359..0ef4b664acfeb790d135047bc1c0ff2d0e27def1 100644 (file)
@@ -257,6 +257,11 @@ public class SerializerTestConnector extends AbstractExtensionConnector {
             public void sendDate(Date date) {
                 rpc.sendDate(date);
             }
+
+            @Override
+            public void log(String message) {
+                // Do nothing, used only in the other direction
+            }
         });
     }
 
@@ -271,13 +276,80 @@ public class SerializerTestConnector extends AbstractExtensionConnector {
     }
 
     @Override
-    public ComplexTestBean getState() {
-        return (ComplexTestBean) super.getState();
+    public SerializerTestState getState() {
+        return (SerializerTestState) super.getState();
     }
 
     @Override
     public void onStateChanged(StateChangeEvent stateChangeEvent) {
-        // TODO do something clever
+        rpc.log("state.booleanValue: " + getState().booleanValue);
+        rpc.log("state.booleanObjectValue: " + getState().booleanObjectValue);
+        rpc.log("state.booleanArray: " + getState().booleanArray);
+
+        rpc.log("state.byteValue: " + getState().byteValue);
+        rpc.log("state.byteObjectValue: " + getState().byteObjectValue);
+        rpc.log("state.byteArray: " + getState().byteArray);
+
+        rpc.log("state.charValue: " + getState().charValue);
+        rpc.log("state.charObjectValue: " + getState().charObjectValue);
+        rpc.log("state.charArray: " + String.valueOf(getState().charArray));
+
+        rpc.log("state.intValue: " + getState().intValue);
+        rpc.log("state.intObjectValue: " + getState().intObjectValue);
+        rpc.log("state.intArray: " + getState().intArray);
+
+        rpc.log("state.longValue: " + getState().longValue);
+        rpc.log("state.longObjectValue: " + getState().longObjectValue);
+        rpc.log("state.longArray: " + getState().longArray);
+
+        rpc.log("state.floatValue: " + getState().floatValue);
+        rpc.log("state.floatObjectValue: " + getState().floatObjectValue);
+        rpc.log("state.floatArray: " + getState().floatArray);
+
+        rpc.log("state.doubleValue: " + getState().doubleValue);
+        rpc.log("state.doubleObjectValue: " + getState().doubleObjectValue);
+        rpc.log("state.doubleArray: " + getState().doubleArray);
+
+        /*
+         * TODO public double doubleValue; public Double DoubleValue; public
+         * double[] doubleArray; ;
+         * 
+         * public String string;
+         * 
+         * public String nullString;
+         * 
+         * public Connector connector;
+         * 
+         * public ComplexTestBean complexTestBean; public SimpleTestBean
+         * simpleTestBean; public SimpleTestBean[] simpleTestBeanArray; public
+         * int[][] nestedIntArray; public SimpleTestBean[][] nestedBeanArray;
+         * 
+         * public List<Integer> intList; public List<Connector> connectorList;
+         * public List<SimpleTestBean> simpleTestBeanList;
+         * 
+         * public List<int[]> primitiveArrayList; public List<Integer[]>
+         * objectArrayList; public List<SimpleTestBean[]> beanArrayList;
+         * 
+         * public List<Integer>[] objectListArray; public List<SimpleTestBean>[]
+         * beanListArray;
+         * 
+         * public Set<Integer> intSet; public Set<Connector> connectorSet;
+         * public Set<SimpleTestBean> beanSet;
+         * 
+         * public Map<String, SimpleTestBean> stringMap; public Map<Connector,
+         * SimpleTestBean> connectorMap; public Map<Integer, Connector> intMap;
+         * public Map<SimpleTestBean, SimpleTestBean> beanMap;
+         * 
+         * public Map<Set<SimpleTestBean>, Map<Integer, List<SimpleTestBean>>>
+         * generics;
+         * 
+         * public ContentMode contentMode; public ContentMode[] array; public
+         * List<ContentMode> list;
+         * 
+         * public SimpleTestBean bean;
+         * 
+         * public Date date1; public Date date2;
+         */
     }
 
     @Override
index 1c0784d8b411cc348a1b6a473c28c54d83a9a8a4..6b4c4e7ac11ed789e89e8684bc3b0bc4ff00b666 100644 (file)
@@ -81,4 +81,6 @@ public interface SerializerTestRpc extends ServerRpc, ClientRpc {
     public void sendBeanSubclass(SimpleTestBean bean);
 
     public void sendDate(Date date);
+
+    public void log(String string);
 }
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/SerializerTestState.java b/uitest/src/com/vaadin/tests/widgetset/client/SerializerTestState.java
new file mode 100644 (file)
index 0000000..d22165b
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * 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.tests.widgetset.client;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.vaadin.shared.AbstractComponentState;
+import com.vaadin.shared.Connector;
+import com.vaadin.shared.ui.label.ContentMode;
+
+public class SerializerTestState extends AbstractComponentState {
+
+    public boolean booleanValue;
+    public Boolean booleanObjectValue;
+    public boolean[] booleanArray;
+
+    public byte byteValue;
+    public Byte byteObjectValue;
+    public byte[] byteArray;
+
+    public char charValue;
+    public Character charObjectValue;
+    public char[] charArray;
+
+    public int intValue;
+    public Integer intObjectValue;
+    public int[] intArray;
+
+    public long longValue;
+    public Long longObjectValue;
+    public long[] longArray;
+
+    public float floatValue;
+    public Float floatObjectValue;
+    public float[] floatArray;
+
+    public double doubleValue;
+    public Double doubleObjectValue;
+    public double[] doubleArray;
+
+    public String string;
+
+    public String nullString;
+
+    public Connector connector;
+
+    public ComplexTestBean complexTestBean;
+    public SimpleTestBean simpleTestBean;
+    public SimpleTestBean[] simpleTestBeanArray;
+    public int[][] nestedIntArray;
+    public SimpleTestBean[][] nestedBeanArray;
+
+    public List<Integer> intList;
+    public List<Connector> connectorList;
+    public List<SimpleTestBean> simpleTestBeanList;
+
+    public List<int[]> primitiveArrayList;
+    public List<Integer[]> objectArrayList;
+    public List<SimpleTestBean[]> beanArrayList;
+
+    public List<Integer>[] objectListArray;
+    public List<SimpleTestBean>[] beanListArray;
+
+    public Set<Integer> intSet;
+    public Set<Connector> connectorSet;
+    public Set<SimpleTestBean> beanSet;
+
+    public Map<String, SimpleTestBean> stringMap;
+    public Map<Connector, SimpleTestBean> connectorMap;
+    public Map<Integer, Connector> intMap;
+    public Map<SimpleTestBean, SimpleTestBean> beanMap;
+
+    public Map<Set<SimpleTestBean>, Map<Integer, List<SimpleTestBean>>> generics;
+
+    public ContentMode contentMode;
+    public ContentMode[] array;
+    public List<ContentMode> list;
+
+    public SimpleTestBean bean;
+
+    public Date date1;
+    public Date date2;
+
+}
index c42b8749c211fa345c9b5d551276673c9f6f2093..5fc5c19497e72231f8bd0a45148320591636a7f1 100644 (file)
@@ -18,8 +18,8 @@ package com.vaadin.tests.widgetset.server;
 
 import com.vaadin.server.AbstractExtension;
 import com.vaadin.shared.communication.ClientRpc;
-import com.vaadin.tests.widgetset.client.ComplexTestBean;
 import com.vaadin.tests.widgetset.client.SerializerTestRpc;
+import com.vaadin.tests.widgetset.client.SerializerTestState;
 
 public class SerializerTestExtension extends AbstractExtension {
 
@@ -29,8 +29,8 @@ public class SerializerTestExtension extends AbstractExtension {
     }
 
     @Override
-    public ComplexTestBean getState() {
-        return (ComplexTestBean) super.getState();
+    public SerializerTestState getState() {
+        return (SerializerTestState) super.getState();
     }
 
     public void registerRpc(SerializerTestRpc rpc) {