extra factory method and type descriptor for NULL defined
This commit is contained in:
parent
5a0522e203
commit
bdecf6720e
|
|
@ -29,9 +29,17 @@ import org.springframework.util.Assert;
|
||||||
* Type metadata about a bindable target value.
|
* Type metadata about a bindable target value.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
|
* @author Andy Clement
|
||||||
|
*
|
||||||
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class TypeDescriptor {
|
public class TypeDescriptor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constant value typeDescriptor for the type of a null value
|
||||||
|
*/
|
||||||
|
public final static TypeDescriptor NULL_TYPE_DESCRIPTOR = new TypeDescriptor((Class<?>)null);
|
||||||
|
|
||||||
private MethodParameter methodParameter;
|
private MethodParameter methodParameter;
|
||||||
|
|
||||||
private Field field;
|
private Field field;
|
||||||
|
|
@ -79,8 +87,10 @@ public class TypeDescriptor {
|
||||||
return type;
|
return type;
|
||||||
} else if (field != null) {
|
} else if (field != null) {
|
||||||
return field.getType();
|
return field.getType();
|
||||||
} else {
|
} else if (methodParameter!=null) {
|
||||||
return methodParameter.getParameterType();
|
return methodParameter.getParameterType();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,9 +253,24 @@ public class TypeDescriptor {
|
||||||
* @return the type descriptor
|
* @return the type descriptor
|
||||||
*/
|
*/
|
||||||
public static TypeDescriptor valueOf(Class<? extends Object> type) {
|
public static TypeDescriptor valueOf(Class<? extends Object> type) {
|
||||||
|
// TODO needs a cache for common type descriptors
|
||||||
return new TypeDescriptor(type);
|
return new TypeDescriptor(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new type descriptor for the class of the given object.
|
||||||
|
* @param object the object
|
||||||
|
* @return the type descriptor
|
||||||
|
*/
|
||||||
|
public static TypeDescriptor forObject(Object object) {
|
||||||
|
if (object==null) {
|
||||||
|
return NULL_TYPE_DESCRIPTOR;
|
||||||
|
} else {
|
||||||
|
return valueOf(object.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal helpers
|
// internal helpers
|
||||||
|
|
||||||
private Class<?> getArrayComponentType() {
|
private Class<?> getArrayComponentType() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue