Change-Id: I75ee98c36bf57483025157d0bd2039e3f6553aectags/7.4.0.beta1
@@ -16,6 +16,8 @@ | |||
package com.vaadin.data.util; | |||
import static com.vaadin.util.ReflectTools.convertPrimitiveType; | |||
import java.io.IOException; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Method; | |||
@@ -551,30 +553,6 @@ public class MethodProperty<T> extends AbstractProperty<T> { | |||
return getMethod; | |||
} | |||
static Class<?> convertPrimitiveType(Class<?> type) { | |||
// Gets the return type from get method | |||
if (type.isPrimitive()) { | |||
if (type.equals(Boolean.TYPE)) { | |||
type = Boolean.class; | |||
} else if (type.equals(Integer.TYPE)) { | |||
type = Integer.class; | |||
} else if (type.equals(Float.TYPE)) { | |||
type = Float.class; | |||
} else if (type.equals(Double.TYPE)) { | |||
type = Double.class; | |||
} else if (type.equals(Byte.TYPE)) { | |||
type = Byte.class; | |||
} else if (type.equals(Character.TYPE)) { | |||
type = Character.class; | |||
} else if (type.equals(Short.TYPE)) { | |||
type = Short.class; | |||
} else if (type.equals(Long.TYPE)) { | |||
type = Long.class; | |||
} | |||
} | |||
return type; | |||
} | |||
/** | |||
* Returns the type of the Property. The methods <code>getValue</code> and | |||
* <code>setValue</code> must be compatible with this type: one must be able |
@@ -21,6 +21,7 @@ import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.util.ReflectTools; | |||
import com.vaadin.util.SerializerHelper; | |||
/** | |||
@@ -57,7 +58,7 @@ public class MethodPropertyDescriptor<BT> implements | |||
public MethodPropertyDescriptor(String name, Class<?> propertyType, | |||
Method readMethod, Method writeMethod) { | |||
this.name = name; | |||
this.propertyType = propertyType; | |||
this.propertyType = ReflectTools.convertPrimitiveType(propertyType); | |||
this.readMethod = readMethod; | |||
this.writeMethod = writeMethod; | |||
} | |||
@@ -98,7 +99,7 @@ public class MethodPropertyDescriptor<BT> implements | |||
@SuppressWarnings("unchecked") | |||
// business assumption; type parameters not checked at runtime | |||
Class<BT> class1 = (Class<BT>) SerializerHelper.readClass(in); | |||
propertyType = class1; | |||
propertyType = ReflectTools.convertPrimitiveType(class1); | |||
String name = (String) in.readObject(); | |||
Class<?> writeMethodClass = SerializerHelper.readClass(in); |
@@ -15,6 +15,8 @@ | |||
*/ | |||
package com.vaadin.data.util; | |||
import static com.vaadin.util.ReflectTools.convertPrimitiveType; | |||
import java.io.IOException; | |||
import java.lang.reflect.InvocationTargetException; | |||
import java.lang.reflect.Method; | |||
@@ -173,8 +175,7 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> { | |||
} catch (final NoSuchMethodException skipped) { | |||
} | |||
this.type = (Class<? extends T>) MethodProperty | |||
.convertPrimitiveType(type); | |||
this.type = (Class<? extends T>) convertPrimitiveType(type); | |||
this.propertyName = propertyName; | |||
this.getMethods = getMethods; | |||
this.setMethod = setMethod; |
@@ -186,4 +186,28 @@ public class ReflectTools implements Serializable { | |||
} | |||
field.set(object, value); | |||
} | |||
public static Class<?> convertPrimitiveType(Class<?> type) { | |||
// Gets the return type from get method | |||
if (type.isPrimitive()) { | |||
if (type.equals(Boolean.TYPE)) { | |||
type = Boolean.class; | |||
} else if (type.equals(Integer.TYPE)) { | |||
type = Integer.class; | |||
} else if (type.equals(Float.TYPE)) { | |||
type = Float.class; | |||
} else if (type.equals(Double.TYPE)) { | |||
type = Double.class; | |||
} else if (type.equals(Byte.TYPE)) { | |||
type = Byte.class; | |||
} else if (type.equals(Character.TYPE)) { | |||
type = Character.class; | |||
} else if (type.equals(Short.TYPE)) { | |||
type = Short.class; | |||
} else if (type.equals(Long.TYPE)) { | |||
type = Long.class; | |||
} | |||
} | |||
return type; | |||
} | |||
} |
@@ -57,12 +57,19 @@ public class NestedMethodPropertyTest extends TestCase { | |||
public static class Person implements Serializable { | |||
private String name; | |||
private Address address; | |||
private int age; | |||
public Person(String name, Address address) { | |||
this.name = name; | |||
this.address = address; | |||
} | |||
public Person(String name, Address address, int age) { | |||
this.name = name; | |||
this.address = address; | |||
this.age = age; | |||
} | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
@@ -78,6 +85,14 @@ public class NestedMethodPropertyTest extends TestCase { | |||
public Address getAddress() { | |||
return address; | |||
} | |||
public int getAge() { | |||
return age; | |||
} | |||
public void setAge(int age) { | |||
this.age = age; | |||
} | |||
} | |||
public static class Team implements Serializable { |
@@ -69,4 +69,12 @@ public class PropertyDescriptorTest extends TestCase { | |||
Assert.assertNull(property.getValue()); | |||
} | |||
public void testMethodPropertyDescriptorWithPrimitivePropertyType() | |||
throws Exception { | |||
MethodPropertyDescriptor<Person> pd = new MethodPropertyDescriptor<Person>( | |||
"age", int.class, Person.class.getMethod("getAge"), | |||
Person.class.getMethod("setAge", int.class)); | |||
Assert.assertEquals(Integer.class, pd.getPropertyType()); | |||
} | |||
} |