1212
Adds support for 'super()' calls. · kurtli/java2python@f4725cc · GitHub
Skip to content

Commit f4725cc

Browse files
author
Troy Melhase
committed
Adds support for 'super()' calls.
1 parent 7e7fad8 commit f4725cc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

java2python/compiler/visitor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,11 @@ def acceptStaticArrayCreator(self, node, memo):
729729
self.right.left = self.factory.expr()
730730
self.right.left.walk(node.firstChildOfType(tokens.EXPR), memo)
731731

732+
def acceptSuper(self, node, memo):
733+
""" Accept and process a super expression. """
734+
cls = self.parents(lambda c:c.isClass).next()
735+
self.right = self.factory.expr(fs='super({name}, self)'.format(name=cls.name))
736+
732737
def acceptSuperConstructorCall(self, node, memo):
733738
""" Accept and process a super constructor call. """
734739
cls = self.parents(lambda c:c.isClass).next()

test/Super1.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Base {
2+
public int foo(int x) {
3+
return x + 1;
4+
}
5+
}
6+
7+
class Super1 extends Base {
8+
9+
public int foo(int y) {
10+
int retval = super.foo(y);
11+
return retval + 1;
12+
}
13+
14+
public static void main(String[] args) {
15+
16+
Super1 x = new Super1();
17+
18+
System.out.println(x.foo(3));
19+
20+
21+
}
22+
23+
24+
}

0 commit comments

Comments
 (0)