Skip to content

Commit 3012a5f

Browse files
author
Troy Melhase
committed
Docstrings and documentation updates.
1 parent 8be3289 commit 3012a5f

3 files changed

Lines changed: 394 additions & 102 deletions

File tree

‎README‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
About
2+
-----
3+
This package provides tools to (imperfectly) translate java source
4+
code to python source code.
5+
6+
7+
Build
8+
-----
9+
To build the code, install Python_ 2.5 or newer, and install PyAntlr_.
10+
Then run "make" in the top of the package.
11+
12+
.. _Python: http://www.python.org/
13+
.. _PyAntlr: http://www.antlr.org/
14+
15+
16+
Install
17+
-------
18+
19+
To install the package and the scripts into your system, then as the super user, run:
20+
21+
$ python setup.py install
22+
23+
The setup script will install the java2python package in
24+
$PYTHONHOME/site-packages, and install the scripts into a bin
25+
directory.
26+
27+
28+
Use
29+
---
30+
To use the "java_to_python" script, either make and install the
31+
package (as per above), or adjust PYTHONPATH (and possibly PATH) to
32+
include the source directories. Then run the script like so:
33+
34+
$ java_to_python -i input_file.java -o output_file.py
35+
36+
The script has configuration options that you can view:
37+
38+
$ java_to_python -h
39+
40+
41+
Feedback
42+
--------
43+
Drop me a note if you're so inclined: troy@gci.net.

‎lib/defaultconfig.py‎

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
## number of spaces to indent each block
45
indent = 4
56

7+
## prefix for comments
8+
commentPrefix = '##'
9+
10+
## move inner class definitions to the top of their outer class.
11+
## allows the outer class to reference the inner class definition
12+
## later in its definition.
13+
bubbleInnerClasses = True
14+
15+
## if True, classes are scanned for methods that look like accessors.
16+
## Matching methods are renamed and declared as properties.
17+
fixPropMethods = True
18+
19+
## if True, classes are scanned for duplicate method names. Matching
20+
## methods are augmented with the '@overloaded' decorator.
21+
fixOverloadMethods = True
22+
23+
## if True, class methods are sorted by name before output.
24+
sortClassMethods = False
25+
26+
## if True, method modifiers are written as comments prior to method
27+
## declarations.
28+
writeModifiersComments = False
29+
30+
## if True, a default docstring is generated for class statements.
31+
writeClassDocString = True
32+
33+
## if True, a default docstring is generated for method statements.
34+
writeMethodDocString = False
35+
36+
## if True, classes without base classes will instead inherit from
37+
## object.
38+
classesInheritObject = True
39+
40+
## minimum parameter count to trigger indentation of parameter names
41+
## in method declarations. set to 0 to disable.
42+
minIndentParams = 5
43+
44+
## lines written at the beginning of each generated module. this value
45+
## is cumulative, so when user-defined configuration modules specify
46+
## this value, those lines are written after these.
47+
modulePreamble = [
48+
'#!/usr/bin/env python',
49+
'# -*- coding: utf-8 -*-',
50+
'',
51+
]
652

53+
## regular expression substitutions performed on source after
54+
## generation but before final output. this value is cumulative, so
55+
## user-defined configuration modules can add augment these with their
56+
## own. each value in this list is a two-tuple of (pattern, repl).
57+
## see the 're' module docs, specifically the re.sub function.
758
outputSubs = [
859
(r'(\.self\.)', '.'),
960
(r'String\.valueOf\((.*?)\)', r'str(\1)'),
@@ -14,7 +65,8 @@
1465
(r'(\w+)\.get\((.*?)\)', r'\1[\2]'),
1566
]
1667

17-
68+
## mapping of java type names to python type names. user-defined
69+
## configuration modules can replace and/or augment this mapping.
1870
typeTypeMap = {
1971
'String':'str',
2072
'int':'int',
@@ -23,7 +75,8 @@
2375
'boolean':'bool',
2476
}
2577

26-
78+
## mapping of java type values to python type values. user-defined
79+
## configuration modules can replace and/or augment this mapping.
2780
typeValueMap = {
2881
'String':'""',
2982
'int':'0',
@@ -33,37 +86,25 @@
3386
'str':'""',
3487
}
3588

36-
89+
## method name mapping. user-defined configuration modules can
90+
## replace and/or augment this with their own.
3791
renameMethodMap = {
3892
'equals':'__eq__'
3993
}
4094

41-
95+
## generic name mapping. user-defined configuration modules can
96+
## replace and/or augment this with their own.
4297
renameAnyMap = {
4398
'this':'self',
4499
'null':'None',
45100
'false':'False',
46101
'true':'True',
47102
}
48103

49-
104+
## method type modifier mapping. when input methods have modifiers
105+
## with matching names, those names are replaced with their
106+
## corresponding statements from this mapping. this value can be
107+
## replaced and/or augmented via user-defined configuration modules.
50108
modifierDecoratorMap = {
51109
'synchronized':'## original method synchronized'
52110
}
53-
54-
55-
modulePreable = [
56-
'#!/usr/bin/env python',
57-
'# -*- coding: utf-8 -*-',
58-
'',
59-
]
60-
61-
62-
bubbleInnerClasses = True
63-
scanPropMethods = True
64-
scanOverloadMethods = True
65-
sortClassMethods = False
66-
writeModifiersComments = False
67-
writeClassDocString = True
68-
69-
commentPrefix = '##'

0 commit comments

Comments
 (0)