Skip to content

Instantly share code, notes, and snippets.

@Naddiseo
Created May 2, 2012 21:50
Show Gist options
  • Save Naddiseo/87c16eef54496e99b8ef to your computer and use it in GitHub Desktop.
Save Naddiseo/87c16eef54496e99b8ef to your computer and use it in GitHub Desktop.
Add "pass" to empty if/else statements
diff --git a/java2python/compiler/visitor.py b/java2python/compiler/visitor.py
index 3b55e31..5307b8b 100644
--- a/java2python/compiler/visitor.py
+++ b/java2python/compiler/visitor.py
@@ -466,11 +466,14 @@ class MethodContent(Base):
else:
ifBlock = self.factory.methodContent(parent=self)
ifBlock.walk(node.children[1], memo)
+
+ if len(children[1].children) == 0:
+ self.factory.statement('pass', parent=ifBlock)
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,16 +482,23 @@ class MethodContent(Base):
else:
nextBlock = self.factory.methodContent(parent=self)
nextBlock.walk(nextNode.children[1], memo)
+
+ if len(nextNode.children[1].children) == 0:
+ self.factory.statement('pass', parent=nextBlock)
+
nextNode = nextNode.children[2]
nextType = nextNode.type
+
if nextType == tokens.EXPR:
elseStat = self.factory.statement('else', fs=FS.lc, parent=self)
elseBlock = self.factory.expr(parent=elseStat)
elseBlock.walk(nextNode, memo)
else: # nextType != tokens.BLOCK_SCOPE:
- self.factory.statement('else', fs=FS.lc, parent=self)
+ elseStat = self.factory.statement('else', fs=FS.lc, parent=self)
self.factory.methodContent(parent=self).walk(nextNode, memo)
+ if len(nextNode.children) == 0:
+ self.factory.statement('pass', parent=elseStat)
def acceptSwitch(self, node, memo):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment