diff --git a/generator/java_code_files/JavaCodeFile.py b/generator/java_code_files/JavaCodeFile.py index cb3cc181..3059ac6c 100644 --- a/generator/java_code_files/JavaCodeFile.py +++ b/generator/java_code_files/JavaCodeFile.py @@ -406,8 +406,10 @@ def write_general_functions(self): self.prime_numbers) - - + self.line_length = 150 + code = gen_functions.write_get_child_at() + self.write_function_implementation(code) + self.line_length = 79 code = gen_functions.write_hashcode() self.write_function_implementation(code) diff --git a/generator/java_code_files/java_functions/GeneralFunctions.py b/generator/java_code_files/java_functions/GeneralFunctions.py index cde7add9..2648d572 100644 --- a/generator/java_code_files/java_functions/GeneralFunctions.py +++ b/generator/java_code_files/java_functions/GeneralFunctions.py @@ -184,6 +184,137 @@ def expand_methods_to_write(self): print('self write ', self.methods_to_write) + ######################################################################## + + + #Function for writing get_child_at + def create_nested_if_for_get_child_at(self, lo_element): + name = lo_element['name'] + cap_name = lo_element['capAttName'] + # print('lo name ',name) + # print('lo capname ', cap_name) + # name = self.attributes[index]['capAttName'] + # member_name = self.attributes[index]['name'] + # type = self.attributes[index]['type'] + # + # curr_att_type = attribute['JClassType'] + # oldValue = 'old{0}'.format(strFunctions.upper_first(attribute['name'])) + # currValue = 'this.{0}'.format(attribute['name']) + # + # implement_part1 = '{0} {1} = this.{2}'.format(curr_att_type, oldValue, attribute['name']) + # implement_part2 = '{0} = {1}'.format(currValue, attribute['name']) + # implement_part3 = 'firePropertyChange({0}Constants.{1}, {2}, {3})'.format(self.package, + # attribute['name'], + # oldValue, + # currValue) + # + # # code = [dict({'code_type': 'line', 'code': 'TADA'})] + implementation = ['pos == index', + 'return getListOf{0}s'.format(cap_name)] # 3rd line + # + nested_if = self.create_code_block('if', implementation) + implementation = ['isSetListOf{0}s'.format(cap_name), + nested_if, 'pos++'] # 2nd line + # # print('implementation ',implementation) + # # code.append(self.create_code_block('if', implementation)) + # code = [self.create_code_block('if', implementation)] + # + # implementationNext = ['return false'] # 1st line + # code.append(self.create_code_block('line', implementationNext)) + # + temp_code = self.create_code_block('if', implementation) + return temp_code + + + + + def write_get_child_at(self): + if len(self.child_lo_elements) == 0: + return + # do not write for C API + if self.is_java_api is False: + return + # create doc string header + function = 'getChildAt' + + title_line = '(non-Javadoc)--@see org.sbml.jsbml.AbstractSBase#getChildAt(int)' + params = [] + + return_lines = [] + additional = [] + additional.append('Override') + + # create function decl + + return_type = 'TreeNode' + arguments = ['int index'] + # create the function implementation + + constructor_args = [] # arguments #self.write_copy_constructor_args(self) + code = [] + clone = 'clone' + + + implementation = [] + implementation.append('index < 0') + implementation.append('throw new IndexOutOfBoundsException(MessageFormat.format('\ + 'resourceBundle.getString("IndexSurpassesBoundsException"), index, 0))') + code.append(self.create_code_block('if', implementation)) + + + implementation = [] + implementation.append('int count = super.getChildCount(), pos = 0') + code.append(self.create_code_block('line', implementation)) + + + implementation = ['index < count'] + implementation.append('return super.getChildAt(index)') + implementation.append('else') + implementation.append('index -= count') + + code.append(self.create_code_block('if_else', implementation)) + + + # additional_add, class_key, function_args = jsbmlHelperFunctions.determine_override_or_deprecated( + # self.jsbml_methods, + # function=function, + # return_type=return_type) + # + # if additional_add is not None: + # additional.append(additional_add) + # title_line = jsbmlHelperFunctions.get_javadoc_comments_and_state(additional_add, class_key, + # function, function_args) + + + for i in range(0, len(self.child_lo_elements)): + lo_element = self.child_lo_elements[i] + temp_code = self.create_nested_if_for_get_child_at(lo_element) + code.append(temp_code) + + # temp = ['return hashCode'] + # code.append(self.create_code_block('line', temp)) + + implementation= ['throw new IndexOutOfBoundsException(MessageFormat.format(\ + resourceBundle.getString("IndexExceedsBoundsException"),\ + index, Math.min(pos, 0)))'] + + code.append(self.create_code_block('line', implementation)) + + return dict({'title_line': title_line, + 'params': params, + 'return_lines': return_lines, + 'additional': additional, + 'function': function, + 'return_type': return_type, + 'arguments': arguments, + 'constant': False, + 'virtual': False, + 'object_name': self.object_name, + 'implementation': code, + 'constructor_args': constructor_args}) + + + ######################################################################## # Functions for writing hashCode def create_hashcode_if(self, index): diff --git a/generator/java_code_files/java_functions/SetGetFunctions.py b/generator/java_code_files/java_functions/SetGetFunctions.py index 5d654be6..5d2bbb75 100644 --- a/generator/java_code_files/java_functions/SetGetFunctions.py +++ b/generator/java_code_files/java_functions/SetGetFunctions.py @@ -2041,6 +2041,8 @@ def set_java_attribute(self, attribute, write_for = 'String'): # atts) # code.append(self.create_code_block('if_else', # implementation)) + + # TODO here's some work that needs to be done element and vector elif 'isVector' in attribute and attribute['isVector']: implementation = ['{0} = {1}'.format(member, name), 'return {0}'.format(self.success)] diff --git a/generator/util/insideJSBML_parser.py b/generator/util/insideJSBML_parser.py index e3536951..b98ac787 100644 --- a/generator/util/insideJSBML_parser.py +++ b/generator/util/insideJSBML_parser.py @@ -4,17 +4,10 @@ file_path = os.path.dirname(os.path.abspath(__file__)) - -# -# print(sys.platform) - - -# command = 'javap -p org.sbml.jsbml.CompartmentalizedSBase' - jsbml_jar = 'jsbml-1.1-with-dependencies.jar' curr_dir = os.getcwd() -print('curr_dir ',curr_dir) +# print('curr_dir ',curr_dir) def print_output(output): @@ -168,9 +161,8 @@ def parse_output(output): def get_class_information(class_name=None, individual_run=False): class_name = 'org.sbml.jsbml.{0}'.format(class_name) - # if individual_run == False: - # command = 'javap -cp {0}{1}{2} -package {3}'.format(file_path, os.sep, jsbml_jar, class_name) - # else: + + command = 'javap -cp {0}{1}{2} -package {3}'.format(file_path, os.sep, jsbml_jar, class_name) # print('command ',command) try: