def generate_c2j_swap(element, object_ref_name, struct_ref_name): msg_java_name = element.java_name_lower setters = [] for field in element.fields: field_type = field.type if is_retval(field): # For retval don't generate setters and generate retval check continue elif is_array(field): jni_name = "" template = _ARRAY_C2J_SWAP_TEMPLATE if field_type.is_swap_needed else _ARRAY_C2J_NO_SWAP_TEMPLATE if isinstance(field_type.base_type, Class): template = _ARRAY_C2J_CLASS_SWAP_TEMPLATE jni_name = field_type.base_type.jni_name setters.append( template.substitute( field_reference_name=field.java_name, class_ref_name=msg_java_name, jni_signature=field_type.jni_signature, jni_type=field_type.jni_type, jni_name=jni_name, base_type=field_type.base_type.jni_accessor, field_length=_generate_array_length( field, struct_ref_name), jni_base_type=field_type.base_type.jni_type, object_ref_name=object_ref_name, struct_ref_name=struct_ref_name, net_to_host_function=field_type.net_to_host_function, c_name=field.name)) else: if field_type.is_swap_needed: template = _SIMPLE_TYPE_FIELD_SETTER_TEMPLATE jni_name = "" if isinstance(field_type, Class): template = _STRUCT_SETTER_TEMPLATE jni_name = field_type.jni_name setters.append( template.substitute( java_name=field.java_name, class_ref_name=msg_java_name, jni_signature=field_type.jni_signature, jni_name=jni_name, jni_accessor=field_type.jni_accessor, object_ref_name=object_ref_name, struct_ref_name=struct_ref_name, net_to_host_function=field_type.net_to_host_function, c_name=field.name)) else: setters.append( _SIMPLE_TYPE_NO_SWAP_FIELD_SETTER_TEMPLATE.substitute( java_name=field.java_name, class_ref_name=msg_java_name, jni_signature=field_type.jni_signature, jni_accessor=field_type.jni_accessor, object_ref_name=object_ref_name, struct_ref_name=struct_ref_name, c_name=field.name)) return "".join(setters)
def generate_c2j_swap(element, object_ref_name, struct_ref_name, is_alias): msg_java_name = element.java_name_lower initialization = [] for field in element.fields: if is_retval(field): # For retval don't generate setters and generate retval check continue elif is_array(field): initialization.append(_generate_c2j_array_swap(msg_java_name, field, object_ref_name, struct_ref_name, is_alias)) else: initialization.append(_generate_c2j_scalar_swap(msg_java_name, field, object_ref_name, struct_ref_name, is_alias)) return "".join(initialization)
def _generate_event_dto(msg, model): msg_java_name_upper = msg.java_name_upper # Negative retval is mapped to java exception, so filter it out: fields = filter(lambda field: not is_retval(field), msg.fields) return _EVENT_TEMPLATE.substitute( plugin_package=model.plugin_package, json_filename=model.json_api_files, json_definition=msg.doc, class_name=msg_java_name_upper, fields=generate_fields(fields), hash_code=generate_hash_code(fields), equals=generate_equals(msg_java_name_upper, fields), to_string=generate_to_string(msg_java_name_upper, fields))
def _generate_error_handler(msg): err_handler = "" for field in msg.fields: if is_retval(field): err_handler = _ERR_HANDLER_TEMPLATE.substitute(name=msg.name) return err_handler