Skip to content

Instantly share code, notes, and snippets.

@Naddiseo
Created May 2, 2012 21:38
Show Gist options
  • Save Naddiseo/2580705 to your computer and use it in GitHub Desktop.
Save Naddiseo/2580705 to your computer and use it in GitHub Desktop.
diff --git a/java2python/compiler/visitor.py b/java2python/compiler/visitor.py
index 3b55e31..4ac6315 100644
--- a/java2python/compiler/visitor.py
+++ b/java2python/compiler/visitor.py
@@ -470,7 +470,8 @@ class MethodContent(Base):
if len(children) == 3:
nextNode = children[2]
nextType = nextNode.type
-
+
+
while nextType == tokens.IF:
nextStat = self.factory.statement('elif', fs=FS.lsrc, parent=self)
nextStat.expr.walk(nextNode.children[0], memo)
@@ -479,13 +480,20 @@ class MethodContent(Base):
else:
nextBlock = self.factory.methodContent(parent=self)
nextBlock.walk(nextNode.children[1], memo)
- nextNode = nextNode.children[2]
- nextType = nextNode.type
+ try:
+ nextNode = nextNode.children[2]
+ nextType = nextNode.type
+ except IndexError:
+ nextType = None # A missing else
+ break
+
if nextType == tokens.EXPR:
elseStat = self.factory.statement('else', fs=FS.lc, parent=self)
elseBlock = self.factory.expr(parent=elseStat)
elseBlock.walk(nextNode, memo)
+ elif nextType is None: # elseif without an else
+ pass
else: # nextType != tokens.BLOCK_SCOPE:
self.factory.statement('else', fs=FS.lc, parent=self)
self.factory.methodContent(parent=self).walk(nextNode, memo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment