Skip to content

Commit 876e40c

Browse files
author
Troy Melhase
committed
Support for super ctor calls (thanks Laurie\!). Closes natural#2.
1 parent 8e8abff commit 876e40c

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

java2python/lib/sourcetypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ def addBaseClass(self, name):
496496
@return None
497497
"""
498498
if name and (name not in self.bases):
499+
name = self.formatExpression(name)
499500
self.bases.append(name)
500501

501502
def formatDecl(self):

java2python/lib/walker.g

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,16 @@ ctor_call [block]
747747
}
748748

749749
| #(SUPER_CTOR_CALL
750-
(el0=expr_list[block]
750+
(seq=expr_list[block]
751751
| p=primary_expr[block] el2=expr_list[block]
752752
)
753-
{raise NotImplementedError("SUPER_CTOR_CALL")}
753+
{
754+
if seq is None:
755+
seq = ""
756+
name = block.parent.name
757+
call = ("super(%s, self).__init__(%s)", (("%s", name), ("%s", seq)))
758+
block.addSource(call)
759+
}
754760
)
755761
;
756762

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class SuperCtorTest1 {
2+
public SuperCtorTest1() {}
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class SuperCtorTest2 {
2+
public SuperCtorTest2() {
3+
super();
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class SuperCtorTest3 {
2+
public SuperCtorTest2() {
3+
super("arg");
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class SuperCtorTest4 {
2+
public SuperCtorTest4(int arg) {
3+
super(arg);
4+
}
5+
}
6+

0 commit comments

Comments
 (0)