Skip to content

Commit 4ea8366

Browse files
author
Troy Melhase
committed
Adds type and modifier attributes to expr block objects.
1 parent be556d5 commit 4ea8366

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

java2python/compiler/template.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ def __repr__(self):
309309
if isinstance(self.right, (basestring, )) and self.right:
310310
parts.append(colors.white('right:') + colors.yellow(self.right))
311311
showfs = False
312+
if self.modifiers:
313+
parts.append(colors.white('modifiers:') + colors.cyan(','.join(self.modifiers)))
314+
if self.type:
315+
parts.append(colors.white('type:') + colors.cyan(self.type))
312316
if showfs:
313317
parts.append(colors.white('format:') + colors.yellow(self.fs))
314318
if self.tail:

java2python/compiler/visitor.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def makeAcceptType(ft):
118118
""" Creates an accept function for the given factory type. """
119119
def acceptType(self, node, memo):
120120
""" Creates and returns a new template for a type. """
121-
name = node.firstChildOfType(tokens.IDENT).text
121+
try:
122+
name = node.firstChildOfType(tokens.IDENT).text
123+
except (AttributeError, ):
124+
return
122125
self.variables.append(name)
123126
return getattr(self.factory, ft)(name=name, parent=self)
124127
return acceptType
@@ -201,9 +204,15 @@ def acceptVarDeclaration(self, node, memo):
201204
for varDecl in varDecls.childrenOfType(tokens.VAR_DECLARATOR):
202205
ident = varDecl.firstChildOfType(tokens.IDENT)
203206
self.variables.append(ident.text)
207+
204208
identExp = self.factory.expr(left=ident.text, parent=self)
209+
identExp.type = self.nodeTypeToString(node)
210+
if node.firstChildOfType(tokens.MODIFIER_LIST):
211+
identExp.modifiers = [child.text for child in node.firstChildOfType(tokens.MODIFIER_LIST).children]
212+
205213
declExp = varDecl.firstChildOfType(tokens.EXPR)
206214
assgnExp = identExp.pushRight(' = ')
215+
207216
declArr = varDecl.firstChildOfType(tokens.ARRAY_INITIALIZER)
208217
if declExp:
209218
assgnExp.walk(declExp, memo)
@@ -219,8 +228,7 @@ def acceptVarDeclaration(self, node, memo):
219228
if node.firstChildOfType(tokens.TYPE).firstChildOfType(tokens.ARRAY_DECLARATOR_LIST):
220229
val = assgnExp.pushRight('[]')
221230
else:
222-
typ = self.nodeTypeToString(node)
223-
val = assgnExp.pushRight('{0}()'.format(typ))
231+
val = assgnExp.pushRight('{0}()'.format(identExp.type))
224232
return self
225233

226234

0 commit comments

Comments
 (0)