* @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
*/
public Object convert(Object source) {
if (toType.isPrimitive()) {
if (source == null) {
throw new BindingException("Cannot convert null to a primitive"); //$NON-NLS-1$
}
}
if (source != null) {
Class sourceClass = source.getClass();
if (toType.isPrimitive() || sourceClass.isPrimitive()) {
if (sourceClass.equals(toType)
|| isPrimitiveTypeMatchedWithBoxed(sourceClass, toType)) {
return source;
}
throw new BindingException(
"Boxed and unboxed types do not match"); //$NON-NLS-1$
}
if (!toType.isAssignableFrom(sourceClass)) {
throw new BindingException(sourceClass.getName()
+ " is not assignable to " + toType.getName()); //$NON-NLS-1$
}
}
return source;
}