diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-03-24 10:47:53 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2015-03-24 10:47:53 +0200 |
commit | e0f815dc176ed484ae14f49e91936fee3d90825a (patch) | |
tree | fa481e4a0bee8f1e0a4c0371856a68ff0f8f5c27 | |
parent | 3306d80f14cebaee7ddcc50df74708783da86868 (diff) | |
download | vaadin-framework-e0f815dc176ed484ae14f49e91936fee3d90825a.tar.gz vaadin-framework-e0f815dc176ed484ae14f49e91936fee3d90825a.zip |
Revert "Fix Declarative support for primitive float and double properties (#17204)"
This reverts commit 7d4de11c54060286bbc7adfeefa2891f3a461b1d.
3 files changed, 14 insertions, 123 deletions
diff --git a/server/src/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/com/vaadin/ui/declarative/DesignFormatter.java index cc5071fe9d..d2fbf2c765 100644 --- a/server/src/com/vaadin/ui/declarative/DesignFormatter.java +++ b/server/src/com/vaadin/ui/declarative/DesignFormatter.java @@ -19,7 +19,6 @@ import java.io.Serializable; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; import java.util.Collections; import java.util.Date; import java.util.Locale; @@ -111,28 +110,22 @@ public class DesignFormatter implements Serializable { converterMap.put(boolean.class, booleanConverter); // floats and doubles use formatters - final DecimalFormatSymbols symbols = new DecimalFormatSymbols( - new Locale("en_US")); + DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale( + "en_US")); final DecimalFormat fmt = new DecimalFormat("0.###", symbols); fmt.setGroupingUsed(false); - - Converter<String, ?> floatConverter = new StringToFloatConverter() { + converterMap.put(Float.class, new StringToFloatConverter() { @Override - protected NumberFormat getFormat(Locale locale) { + protected java.text.NumberFormat getFormat(Locale locale) { return fmt; }; - }; - converterMap.put(Float.class, floatConverter); - converterMap.put(float.class, floatConverter); - - Converter<String, ?> doubleConverter = new StringToDoubleConverter() { + }); + converterMap.put(Double.class, new StringToDoubleConverter() { @Override - protected NumberFormat getFormat(Locale locale) { + protected java.text.NumberFormat getFormat(Locale locale) { return fmt; }; - }; - converterMap.put(Double.class, doubleConverter); - converterMap.put(double.class, doubleConverter); + }); // strings do nothing converterMap.put(String.class, new Converter<String, String>() { @@ -176,7 +169,7 @@ public class DesignFormatter implements Serializable { }; converterMap.put(Character.class, charConverter); - converterMap.put(char.class, charConverter); + converterMap.put(Character.TYPE, charConverter); converterMap.put(Date.class, new DesignDateConverter()); converterMap.put(ShortcutAction.class, diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java index 0c6cf55bed..d80119bea1 100644 --- a/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java +++ b/server/src/com/vaadin/ui/declarative/converters/DesignToStringConverter.java @@ -64,8 +64,7 @@ public class DesignToStringConverter<TYPE> implements Converter<String, TYPE> { * must be public and static method that returns an object of * passed type. */ - public DesignToStringConverter(Class<? extends TYPE> type, - String staticMethodName) { + public DesignToStringConverter(Class<? extends TYPE> type, String staticMethodName) { this.type = type; this.staticMethodName = staticMethodName; } @@ -82,7 +81,7 @@ public class DesignToStringConverter<TYPE> implements Converter<String, TYPE> { } catch (IllegalArgumentException e) { throw new Converter.ConversionException(e); } catch (InvocationTargetException e) { - throw new Converter.ConversionException(e.getCause()); + throw new Converter.ConversionException(e); } catch (NoSuchMethodException e) { throw new Converter.ConversionException(e); } catch (SecurityException e) { diff --git a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java index 1e6d446427..c7909751a1 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java +++ b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java @@ -53,11 +53,9 @@ public class DesignFormatterTest { @Test public void testSupportedClasses() { - for (Class<?> type : new Class<?>[] { boolean.class, char.class, - byte.class, short.class, int.class, long.class, float.class, - double.class, Boolean.class, Character.class, Byte.class, - Short.class, Integer.class, Long.class, Float.class, - Double.class, String.class, ShortcutAction.class, Date.class, + for (Class<?> type : new Class<?>[] { String.class, Boolean.class, + Integer.class, Float.class, Byte.class, Short.class, + Double.class, ShortcutAction.class, Date.class, FileResource.class, ExternalResource.class, ThemeResource.class, Resource.class, TimeZone.class }) { assertTrue("not supported " + type.getSimpleName(), @@ -66,105 +64,6 @@ public class DesignFormatterTest { } @Test - public void testBoolean() { - assertEquals("true", formatter.format(true)); - assertEquals("false", formatter.format(false)); - - assertEquals(true, formatter.parse("true", boolean.class)); - assertEquals(true, formatter.parse("foobar", boolean.class)); - assertEquals(true, formatter.parse("", boolean.class)); - assertEquals(false, formatter.parse("false", boolean.class)); - - assertEquals(true, formatter.parse("true", Boolean.class)); - assertEquals(true, formatter.parse("foobar", Boolean.class)); - assertEquals(true, formatter.parse("", Boolean.class)); - assertEquals(false, formatter.parse("false", Boolean.class)); - } - - @Test - public void testIntegral() { - byte b = 123; - assertEquals("123", formatter.format(b)); - assertEquals(b, (byte) formatter.parse("123", byte.class)); - assertEquals((Byte) b, formatter.parse("123", Byte.class)); - - b = -123; - assertEquals("-123", formatter.format(b)); - assertEquals(b, (byte) formatter.parse("-123", byte.class)); - assertEquals((Byte) b, formatter.parse("-123", Byte.class)); - - short s = 12345; - assertEquals("12345", formatter.format(s)); - assertEquals(s, (short) formatter.parse("12345", short.class)); - assertEquals((Short) s, formatter.parse("12345", Short.class)); - - s = -12345; - assertEquals("-12345", formatter.format(s)); - assertEquals(s, (short) formatter.parse("-12345", short.class)); - assertEquals((Short) s, formatter.parse("-12345", Short.class)); - - int i = 123456789; - assertEquals("123456789", formatter.format(i)); - assertEquals(i, (int) formatter.parse("123456789", int.class)); - assertEquals((Integer) i, formatter.parse("123456789", Integer.class)); - - i = -123456789; - assertEquals("-123456789", formatter.format(i)); - assertEquals(i, (int) formatter.parse("-123456789", int.class)); - assertEquals((Integer) i, formatter.parse("-123456789", Integer.class)); - - long l = 123456789123456789L; - assertEquals("123456789123456789", formatter.format(l)); - assertEquals(l, - (long) formatter.parse("123456789123456789", long.class)); - assertEquals((Long) l, - formatter.parse("123456789123456789", Long.class)); - - l = -123456789123456789L; - assertEquals("-123456789123456789", formatter.format(l)); - assertEquals(l, - (long) formatter.parse("-123456789123456789", long.class)); - assertEquals((Long) l, - formatter.parse("-123456789123456789", Long.class)); - } - - @Test - public void testFloatingPoint() { - float f = 123.4567f; - assertEquals("123.457", formatter.format(f)); - assertEquals(f, formatter.parse("123.4567", float.class), 1e-4); - assertEquals(f, formatter.parse("123.4567", Float.class), 1e-4); - - double d = 123456789.123456789; - assertEquals("123456789.123", formatter.format(d)); - assertEquals(d, formatter.parse("123456789.123456789", double.class), - 1e-9); - assertEquals(d, formatter.parse("123456789.123456789", Double.class), - 1e-9); - - } - - @Test - public void testChar() { - char c = '\uABCD'; - assertEquals("\uABCD", formatter.format(c)); - assertEquals(c, (char) formatter.parse("\uABCD", char.class)); - assertEquals((Character) c, formatter.parse("\uABCD", Character.class)); - - c = 'y'; - assertEquals(c, (char) formatter.parse("yes", char.class)); - } - - @Test - public void testString() { - - for (String s : new String[] { "", "foobar", "\uABCD", "驯鹿" }) { - assertEquals(s, formatter.format(s)); - assertEquals(s, formatter.parse(s, String.class)); - } - } - - @Test public void testDate() throws Exception { Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2012-02-17"); String formatted = formatter.format(date); |