| 871 | |
| 872 | |
| 873 | class Java(BaseParser): |
| 874 | |
| 875 | function_name_mapping = dict(Props1SI='CoolProp.Props1SI', |
| 876 | PropsSI='CoolProp.PropsSI', |
| 877 | PhaseSI='CoolProp.PhaseSI', |
| 878 | HAPropsSI='CoolProp.HAPropsSI', |
| 879 | get_global_param_string='CoolProp.get_global_param_string', |
| 880 | factory='AbstractState.factory') |
| 881 | type_name_mapping = {'vector': 'DoubleVector', |
| 882 | 'AbstractState': 'AbstractState'} |
| 883 | enum_name_mapping = {'input_pairs': "input_pairs", 'parameters': "parameters"} |
| 884 | indentation = ' ' * 8 |
| 885 | |
| 886 | def parse_arguments(self, arguments): |
| 887 | out = [] |
| 888 | for arg in arguments: |
| 889 | if isinstance(arg, str) and arg[0] == "'" and arg[-1] == "'": |
| 890 | out.append('\"' + arg[1:-1] + '\"') |
| 891 | elif isinstance(arg, dict): |
| 892 | out.append(self.dict2string(arg)) |
| 893 | else: |
| 894 | out.append(arg) |
| 895 | return out |
| 896 | |
| 897 | def dict2string(self, d): |
| 898 | if d['type'] == 'comment': |
| 899 | l = '// ' + d['comment'] |
| 900 | elif d['type'] == 'print': |
| 901 | l = 'System.out.println(' + ' + " " + '.join(self.parse_arguments(d['arguments'])) + ')' |
| 902 | elif d['type'] == 'function': |
| 903 | l = self.map_function(d['function']) + '(' + ', '.join(self.parse_arguments(d['arguments'])) + ')' |
| 904 | elif d['type'] == 'vector': |
| 905 | l = '{' + ', '.join(self.parse_arguments(d['arguments'])) + '}' |
| 906 | elif d['type'] == 'enum': |
| 907 | l = self.enum_name_mapping[d['enum']] + '.' + d['key'] |
| 908 | elif d['type'] == 'class_dereference': |
| 909 | l = d['name'] + '.' + self.dict2string(d['RHS']) |
| 910 | elif d['type'] == 'custom_assignment': |
| 911 | type_name = self.type_name_mapping[d['variable_type']] |
| 912 | if type_name: |
| 913 | LHS = type_name + ' ' + d['variable_name'] |
| 914 | else: |
| 915 | LHS = d['variable_name'] |
| 916 | |
| 917 | if d['RHS']['type'] != 'vector': |
| 918 | RHS = self.dict2string(d['RHS']) |
| 919 | else: # Custom processing for vector assignment |
| 920 | pushes = [d['variable_name'] + '.add(' + arg + ');' for arg in d['RHS']['arguments']] |
| 921 | RHS = 'new DoubleVector(); ' + ' '.join(pushes) |
| 922 | |
| 923 | l = ' '.join([LHS, '=', RHS]) |
| 924 | else: |
| 925 | raise ValueError |
| 926 | |
| 927 | if 'EOL' in d and d['EOL']: |
| 928 | l += ';' |
| 929 | |
| 930 | return l |
no outgoing calls
no test coverage detected