Permalink
Browse files

Added get_child_at method for lo_elements

  • Loading branch information...
hovo1990 committed Jul 23, 2016
1 parent 3f6f906 commit 938fadd83b7b39df7002ec9ade374c64bd84b0d3
@@ -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)
@@ -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):
@@ -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)]
@@ -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:

0 comments on commit 938fadd

Please sign in to comment.