Skip to content

Commit 3153297

Browse files
author
Troy Melhase
committed
Added support for 'methodPreambleSorter' configuration item.
Added extra parens around == expressions in grammar file; removed trailing space from ternary expression.
1 parent 148d012 commit 3153297

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

java2python/lib/defaultconfig.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
'double':'float',
9494
'Vector':'list',
9595
'boolean':'bool',
96+
'char':'str',
9697
}
9798

9899
## mapping of java type values to python type values. user-defined
@@ -159,3 +160,12 @@
159160
'NoSuchFieldError':'AttributeError',
160161
'NoSuchMethodException':'AttributeError',
161162
}
163+
164+
165+
## define this name in your configuration modules to sort decorators
166+
## before they're output. example follows.
167+
methodPreambleSorter = None
168+
169+
## use a block like this to sort decorators by name.
170+
## def methodPreambleSorter(a, b):
171+
## return cmp(a, b)

java2python/lib/sourcetypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ def addParameter(self, typ, name):
660660
@return None
661661
"""
662662
name = self.alternateName(name)
663+
typ = Source.alternateName(self, typ, 'typeTypeMap')
663664
self.parameters.append((typ, name))
664665

665666
def formatDecl(self, indent):
@@ -704,6 +705,10 @@ def writeTo(self, output, indent):
704705
output.write('\n')
705706
if self.config.last('writeModifiersComments'):
706707
output.write('%s## modifiers: %s\n' % (offset, str.join(',', self.modifiers)))
708+
709+
sorter = self.config.last('methodPreambleSorter')
710+
if sorter:
711+
self.preamble.sort(sorter)
707712
for obj in self.preamble:
708713
output.write('%s%s\n' % (offset, obj))
709714
output.write('%s\n' % (self.formatDecl(indent), ))

java2python/lib/walker.g

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ returns [exp]
526526
expr [block]
527527
returns [exp = block.unknownExpression]
528528
: #(QUESTION a0=expr[block] b0=expr[block] c0=expr[block])
529-
{exp = ("%s %s ", (("%s", b0), ("%s %s", (("if %s", a0), ("else %s", c0)))))}
529+
{exp = ("%s %s", (("%s", b0), ("%s %s", (("if %s", a0), ("else %s", c0)))))}
530530

531531
| #(ASSIGN left=expr[block] right=expr[block])
532532
{exp = ("%s = %s", (left, right))}
@@ -588,7 +588,7 @@ returns [exp = block.unknownExpression]
588588
if right in ("None", (("%s", "None"))):
589589
exp = ("%s is %s", (left, right))
590590
else:
591-
exp = ("%s == %s", (left, right))
591+
exp = ("(%s == %s)", (left, right))
592592
}
593593

594594
| #(LT left=expr[block] right=expr[block])

0 commit comments

Comments
 (0)