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: patch-diff.githubusercontent.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:c2ecd406-c0ea-0b5e-fde7-1e401f925e92 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D526:DA633:86754DE:AD60297:6975E32F |
| html-safe-nonce | 716e8dbc0e707f4b9b1ed28227f8ea36426a5d4b7b26c16f938b61702c8c223c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTI2OkRBNjMzOjg2NzU0REU6QUQ2MDI5Nzo2OTc1RTMyRiIsInZpc2l0b3JfaWQiOiI5MDg2NzI5Njk4NTA2MzAyMjU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f578281a2e5d5bec88b94280b5addee7d65a356bb04bc8b13ff2e55c74ebc49b |
| 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 | 2bce766e7450b03e00b2fc5badd417927ce33a860e78cda3e4ecb9bbd1374cc6 |
| 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 | fcca2b8ef702b5f7f91427a6e920fa44446fe312 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width