You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When converting an existing code base I found that else-if apparently is not supported. Here's an example:
publicstaticvoidmain(String[] args) {
inta = 0;
if (a == 1) {
System.out.println("a=1");
} elseif (a == 2) {
System.out.println("a=2");
}
}
which fails with the output
$ j2py HelloWorld.java
Traceback (most recent call last):
File "/usr/local/bin/j2py", line 258, in <module>
sys.exit(runMain(configScript(sys.argv[1:])))
File "/usr/local/bin/j2py", line 57, in runMain
return runOneOrMany(options)
File "/usr/local/bin/j2py", line 82, in runOneOrMany
return runTransform(options)
File "/usr/local/bin/j2py", line 134, in runTransform
module.walk(tree)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 83, in walk
visitor = self.accept(tree, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 43, in accept
return call(node, memo)
File "/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py", line 474, in acceptIf
nextNode = nextNode.children[2]
With the obvious workaround of separating the if statements, the conversion is successful:
publicstaticvoidmain(String[] args) {
inta = 0;
if (a == 1) {
System.out.println("a=1");
}
if (a == 2) {
System.out.println("a=2");
}
}
converts to
#!/usr/bin/env python""" generated source for module HelloWorld """classHelloWorld(object):
""" generated source for class HelloWorld """@classmethoddefmain(cls, args):
""" generated source for method main """a=0ifa==1:
print"a=1"ifa==2:
print"a=2"if__name__=='__main__':
importsysHelloWorld.main(sys.argv)
The text was updated successfully, but these errors were encountered:
When converting an existing code base I found that else-if apparently is not supported. Here's an example:
which fails with the output
With the obvious workaround of separating the if statements, the conversion is successful:
converts to
The text was updated successfully, but these errors were encountered: