Title: Else if conversion fails · Issue #70 · natural/java2python · GitHub
Open Graph Title: Else if conversion fails · Issue #70 · natural/java2python
X Title: Else if conversion fails · Issue #70 · natural/java2python
Description: When converting an existing code base I found that else-if apparently is not supported. Here's an example: public static void main(String[] args) { int a = 0; if (a == 1) { System.out.println("a=1"); } else if (a == 2) { System.out.print...
Open Graph Description: When converting an existing code base I found that else-if apparently is not supported. Here's an example: public static void main(String[] args) { int a = 0; if (a == 1) { System.out.println("a=1"...
X Description: When converting an existing code base I found that else-if apparently is not supported. Here's an example: public static void main(String[] args) { int a = 0; if (a == 1) { System.out.println(&...
Opengraph URL: https://github.com/natural/java2python/issues/70
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Else if conversion fails","articleBody":"When converting an existing code base I found that else-if apparently is not supported. Here's an example:\r\n\r\n```java\r\n public static void main(String[] args) {\r\n int a = 0;\r\n if (a == 1) {\r\n System.out.println(\"a=1\");\r\n } else if (a == 2) {\r\n System.out.println(\"a=2\");\r\n }\r\n }\r\n```\r\nwhich fails with the output\r\n```\r\n$ j2py HelloWorld.java\r\nTraceback (most recent call last):\r\n File \"/usr/local/bin/j2py\", line 258, in \u003cmodule\u003e\r\n sys.exit(runMain(configScript(sys.argv[1:])))\r\n File \"/usr/local/bin/j2py\", line 57, in runMain\r\n return runOneOrMany(options)\r\n File \"/usr/local/bin/j2py\", line 82, in runOneOrMany\r\n return runTransform(options)\r\n File \"/usr/local/bin/j2py\", line 134, in runTransform\r\n module.walk(tree)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 86, in walk\r\n visitor.walk(child, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 86, in walk\r\n visitor.walk(child, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 86, in walk\r\n visitor.walk(child, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 86, in walk\r\n visitor.walk(child, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 86, in walk\r\n visitor.walk(child, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 83, in walk\r\n visitor = self.accept(tree, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 43, in accept\r\n return call(node, memo)\r\n File \"/usr/local/lib/python2.7/dist-packages/java2python/compiler/visitor.py\", line 474, in acceptIf\r\n nextNode = nextNode.children[2]\r\n```\r\n\r\nWith the obvious workaround of separating the if statements, the conversion is successful:\r\n```java\r\n public static void main(String[] args) {\r\n int a = 0;\r\n if (a == 1) {\r\n System.out.println(\"a=1\");\r\n }\r\n if (a == 2) {\r\n System.out.println(\"a=2\");\r\n }\r\n }\r\n```\r\nconverts to\r\n```python\r\n\r\n#!/usr/bin/env python\r\n\"\"\" generated source for module HelloWorld \"\"\"\r\nclass HelloWorld(object):\r\n \"\"\" generated source for class HelloWorld \"\"\"\r\n @classmethod\r\n def main(cls, args):\r\n \"\"\" generated source for method main \"\"\"\r\n a = 0\r\n if a == 1:\r\n print \"a=1\"\r\n if a == 2:\r\n print \"a=2\"\r\n\r\n\r\nif __name__ == '__main__':\r\n import sys\r\n HelloWorld.main(sys.argv)\r\n```\r\n","author":{"url":"https://github.com/ferchault","@type":"Person","name":"ferchault"},"datePublished":"2020-12-04T15:59:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/70/java2python/issues/70"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:65f36bfd-0543-1180-7040-e255aba46c89 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0EA:2E3F95:13D2A63:1B698B0:696A94F7 |
| html-safe-nonce | 45dac89c9aaffaa3649cf09bfb4e6fe5bcf309a92855be5e6b13f6830642d006 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEVBOjJFM0Y5NToxM0QyQTYzOjFCNjk4QjA6Njk2QTk0RjciLCJ2aXNpdG9yX2lkIjoiMjUyMjk5MzU0MjQwMTAwNDc5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 797511cffe71de10077965f0660e04fe476c81734c76c3bc5638b2374de03a09 |
| hovercard-subject-tag | issue:757210542 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/natural/java2python/70/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7a133fa2b6dad014ae50a50dc3996f527d262dcb4dd46bed1a74175d4b620e5a/natural/java2python/issues/70 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7a133fa2b6dad014ae50a50dc3996f527d262dcb4dd46bed1a74175d4b620e5a/natural/java2python/issues/70 |
| og:image:alt | When converting an existing code base I found that else-if apparently is not supported. Here's an example: public static void main(String[] args) { int a = 0; if (a == 1) { System.out.println("a=1"... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ferchault |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4dd496afc954da9c207b2d9fbe86e3074619f565754aa1d9274aec30d9e5b8d7 |
| turbo-cache-control | no-preview |
| go-import | github.com/natural/java2python git https://github.com/natural/java2python.git |
| octolytics-dimension-user_id | 146692 |
| octolytics-dimension-user_login | natural |
| octolytics-dimension-repository_id | 3298542 |
| octolytics-dimension-repository_nwo | natural/java2python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3298542 |
| octolytics-dimension-repository_network_root_nwo | natural/java2python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 31496a13b80a2f6ad77d6c617ee2255a3545b539 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width