소스 검색

Box and unbox long values in state fields (#14176)

We actually want to pass around the primitive long values emulated by
GWT even though JavaScript code can't do anything with the values.
Skipping the unboxing caused long fields to always be 0 since that's how
JavaScript converts an object into a number.

This patch also makes the test assert that the expected state values are
received and updates those values to actually make sense in some
situations.

Change-Id: Id9c3696d699593bd9e59e249c5daf077873b85fc
tags/7.3.0.rc1
Leif Åstrand 10 년 전
부모
커밋
c5df7f5bf6

+ 2
- 10
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java 파일 보기

@@ -45,25 +45,17 @@ 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(),
shouldUnbox ? unboxValue(valueVariable) : valueVariable);
.getQualifiedSourceName(), getName(), unboxValue(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(shouldBox ? boxValue(value) : value);
w.print(boxValue(value));
w.println(";");
}


+ 4
- 4
uitest/src/com/vaadin/tests/serialization/SerializerTest.java 파일 보기

@@ -93,13 +93,13 @@ public class SerializerTest extends AbstractTestUI {

rpc.sendInt(Integer.MAX_VALUE, Integer.valueOf(0), new int[] { 5, 7 });
state.intValue = Integer.MAX_VALUE;
state.intObjectValue = Integer.valueOf(0);
state.intObjectValue = Integer.valueOf(42);
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.longValue = 577431841359l;
state.longObjectValue = Long.valueOf(577431841360l);
state.longArray = new long[] { -57841235865l, 57 };

rpc.sendFloat(3.14159f, Float.valueOf(Math.nextUp(1)), new float[] {
@@ -111,7 +111,7 @@ public class SerializerTest extends AbstractTestUI {
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.doubleObjectValue = Double.valueOf(-Math.E);
state.doubleArray = new double[] { Double.MAX_VALUE, Double.MIN_VALUE };

rpc.sendString("This is a tesing string ‡");

+ 31
- 0
uitest/src/com/vaadin/tests/serialization/SerializerTestTest.java 파일 보기

@@ -77,5 +77,36 @@ public class SerializerTestTest extends MultiBrowserTest {
"sendBoolean: false, false, [false, false, true, false, true, true]",
getLogRow(logRow++));
Assert.assertEquals("sendBeanSubclass: 43", getLogRow(logRow++));
Assert.assertEquals(
"state.doubleArray: [1.7976931348623157e+308, 5e-324]",
getLogRow(logRow++));
Assert.assertEquals("state.doubleObjectValue: -2.718281828459045",
getLogRow(logRow++));
Assert.assertEquals("state.doubleValue: 3.141592653589793",
getLogRow(logRow++));
Assert.assertEquals("state.floatArray: [57, 0, -12]",
getLogRow(logRow++));
Assert.assertEquals("state.floatObjectValue: 1.0000001",
getLogRow(logRow++));
Assert.assertEquals("state.floatValue: 3.14159", getLogRow(logRow++));
Assert.assertEquals("state.longArray: [-57841235865, 57]",
getLogRow(logRow++));
Assert.assertEquals("state.longObjectValue: 577431841360",
getLogRow(logRow++));
Assert.assertEquals("state.longValue: 577431841359",
getLogRow(logRow++));
Assert.assertEquals("state.intArray: [5, 7]", getLogRow(logRow++));
Assert.assertEquals("state.intObjectValue: 42", getLogRow(logRow++));
Assert.assertEquals("state.intValue: 2147483647", getLogRow(logRow++));
Assert.assertEquals("state.charArray: aBcD", getLogRow(logRow++));
Assert.assertEquals("state.charObjectValue: å", getLogRow(logRow++));
Assert.assertEquals("state.charValue: ∫", getLogRow(logRow++));
Assert.assertEquals("state.byteArray: [3, 1, 2]", getLogRow(logRow++));
Assert.assertEquals("state.byteObjectValue: -12", getLogRow(logRow++));
Assert.assertEquals("state.byteValue: 5", getLogRow(logRow++));
Assert.assertEquals(
"state.booleanArray: [true, true, false, true, false, false]",
getLogRow(logRow++));

}
}

+ 7
- 6
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestConnector.java 파일 보기

@@ -284,11 +284,12 @@ public class SerializerTestConnector extends AbstractExtensionConnector {
public void onStateChanged(StateChangeEvent stateChangeEvent) {
rpc.log("state.booleanValue: " + getState().booleanValue);
rpc.log("state.booleanObjectValue: " + getState().booleanObjectValue);
rpc.log("state.booleanArray: " + getState().booleanArray);
rpc.log("state.booleanArray: "
+ Arrays.toString(getState().booleanArray));

rpc.log("state.byteValue: " + getState().byteValue);
rpc.log("state.byteObjectValue: " + getState().byteObjectValue);
rpc.log("state.byteArray: " + getState().byteArray);
rpc.log("state.byteArray: " + Arrays.toString(getState().byteArray));

rpc.log("state.charValue: " + getState().charValue);
rpc.log("state.charObjectValue: " + getState().charObjectValue);
@@ -296,19 +297,19 @@ public class SerializerTestConnector extends AbstractExtensionConnector {

rpc.log("state.intValue: " + getState().intValue);
rpc.log("state.intObjectValue: " + getState().intObjectValue);
rpc.log("state.intArray: " + getState().intArray);
rpc.log("state.intArray: " + Arrays.toString(getState().intArray));

rpc.log("state.longValue: " + getState().longValue);
rpc.log("state.longObjectValue: " + getState().longObjectValue);
rpc.log("state.longArray: " + getState().longArray);
rpc.log("state.longArray: " + Arrays.toString(getState().longArray));

rpc.log("state.floatValue: " + getState().floatValue);
rpc.log("state.floatObjectValue: " + getState().floatObjectValue);
rpc.log("state.floatArray: " + getState().floatArray);
rpc.log("state.floatArray: " + Arrays.toString(getState().floatArray));

rpc.log("state.doubleValue: " + getState().doubleValue);
rpc.log("state.doubleObjectValue: " + getState().doubleObjectValue);
rpc.log("state.doubleArray: " + getState().doubleArray);
rpc.log("state.doubleArray: " + Arrays.toString(getState().doubleArray));

/*
* TODO public double doubleValue; public Double DoubleValue; public

Loading…
취소
저장