Skip to content

Commit 66852c6

Browse files
committed
Add all required super calls in Groovy translator
1 parent b784919 commit 66852c6

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/translators/groovy.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=protected-access,too-many-instance-attributes,too-many-locals
22
# pylint: disable=too-many-statements
3+
import re
34
from collections import OrderedDict
45

56
from src.ir import ast, groovy_types as gt, types as tp, type_utils as tu
@@ -274,13 +275,31 @@ def construct_constructor():
274275
constructor_fields = "\n" + self.get_ident(extra=2) if fields \
275276
else ""
276277
constructor_fields += ("\n" + self.get_ident(extra=2)).join(fields)
277-
return ("{ident}public {name}({params}) {{{fields}{new_line}"
278-
"{close_ident}}}").format(
278+
super_call = ""
279+
if node.superclasses:
280+
supercls = node.superclasses[0]
281+
if not isinstance(supercls.class_type, tp.Builtin):
282+
res = ""
283+
if supercls.args:
284+
translator = GroovyTranslator()
285+
translator.context = self.context
286+
translator._cast_number = True
287+
translator._namespace = self._namespace
288+
for expr in supercls.args:
289+
translator.visit(expr)
290+
res = translator._children_res
291+
res = ", ".join(res)
292+
res = re.sub(r'\s+', ' ', res)
293+
super_call = "\n" + self.get_ident(extra=2) + 'super(' + \
294+
res + ");"
295+
return ("{ident}public {name}({params}) {{{super_call}{fields}"
296+
"{new_line}{close_ident}}}").format(
279297
ident=self.get_ident(),
280298
name=node.name,
281299
params=constructor_params,
300+
super_call=super_call,
282301
fields=constructor_fields,
283-
new_line="\n" if fields else "",
302+
new_line="\n",
284303
close_ident=self.get_ident() if fields else ""
285304
)
286305

@@ -317,7 +336,7 @@ def construct_constructor():
317336
else:
318337
res += " implements " + ", ".join(interfaces)
319338
body = " {"
320-
if function_res or field_res:
339+
if function_res or field_res or superclasses:
321340
body += "\n"
322341
join_separator = "\n" + self.get_ident()
323342
if field_res:

0 commit comments

Comments
 (0)