1212
Adds support for 'this()' constructor calls. · ivan-mind/java2python@7e7fad8 · GitHub
Skip to content

Commit 7e7fad8

Browse files
author
Troy Melhase
committed
Adds support for 'this()' constructor calls.
1 parent fdff9c4 commit 7e7fad8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

java2python/compiler/visitor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ def acceptMethodCall(self, node, memo):
718718
arg.left.walk(child, memo)
719719
arg.right = arg = expr(parent=self)
720720

721+
def acceptThisConstructorCall(self, node, memo):
722+
""" Accept and process a 'this(...)' constructor call. """
723+
self.acceptMethodCall(node, memo)
724+
self.left = 'self.__init__'
725+
721726
def acceptStaticArrayCreator(self, node, memo):
722727
""" Accept and process a static array expression. """
723728
self.right = self.factory.expr(fs='[None]*{left}')

test/Ctor4.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Ctor4 {
2+
3+
public int m_foo;
4+
public int m_bar;
5+
6+
7+
8+
public Ctor4() {
9+
this(/* foo */ 0, /* bar */ 0);
10+
}
11+
12+
public Ctor4(int p_foo) {
13+
this(p_foo, 0);
14+
15+
}
16+
17+
public Ctor4(int p_foo, int p_bar) {
18+
m_foo = p_foo;
19+
m_bar = p_bar;
20+
}
21+
22+
23+
public static void main(String[] args) {
24+
Ctor4 a = new Ctor4();
25+
System.out.println(a.m_foo);
26+
System.out.println(a.m_bar);
27+
28+
Ctor4 b = new Ctor4(1);
29+
System.out.println(b.m_foo);
30+
System.out.println(b.m_bar);
31+
32+
33+
Ctor4 c = new Ctor4(2, 3);
34+
System.out.println(c.m_foo);
35+
System.out.println(c.m_bar);
36+
37+
}
38+
39+
40+
}

0 commit comments

Comments
 (0)