@@ -8,6 +8,7 @@ line. See the [usage][] page for instructions on specifying additional configs.
88The default configuration module is ` java2python.config.default ` . Refer to [ the source
99of that module] [ 1 ] for its values and additional descriptions.
1010
11+
1112### Usage
1213
1314To change the behavior of some or all of the config items, create a Python
@@ -25,6 +26,7 @@ Then run the script:
2526The config files are Python modules, so you can use the full power of Python
2627when writing your configurations.
2728
29+
2830### A Note About Some of the Names: Prologue, Base, Head, and Epilogue
2931
3032When a config point has ` Prologue ` in its name, it means that the item will be
@@ -35,7 +37,6 @@ the shebang line.
3537When a config point has ` Base ` in the name, it means that the item will be
3638responsible for generating the base classes of a class, enum, or interface.
3739
38-
3940A config point with ` Head ` in the name means that the item will be responsible
4041for generating code for the section between the declaration and the body of the
4142item. For example:
@@ -49,40 +50,207 @@ recognized epilogue config point is `moduleEpilogueHandlers`, which generates a
4950main script stanza if necessary.
5051
5152
53+ ### Override vs. Replace
54+
55+ Many of the config handlers in the default config module are lists or
56+ dictionaries. It may be desirable for your project to supplement or modify
57+ these instead of changing them completely. For example, you could add a module
58+ prologue handler to the existing values. To do so, you would do something like this
59+ in your config:
60+
61+ from java2python.config.default import modulePrologueHandlers
62+
63+ def myPrologue(module):
64+ ...
65+
66+ modulePrologueHandlers.append(myPrologue)
67+
68+ Values can be remove in a similar way:
69+
70+ from java2python.config.default import modulePrologueHandlers
71+ from java2python.mod import basic
72+
73+ modulePrologueHandlers.remove(basic.shebangLine)
74+
75+ In other cases, you can simply redefine the config value altogether:
76+
77+ classHeadHandlers = [myCustomDocStringGenerator]
78+
5279
5380### Customization Points
5481
82+ The remainder of this page lists the recognized config points, their meaning,
83+ and their default values.
84+
85+
5586#### <a name =" indentPrefix " ></a >indentPrefix
87+
88+ Leading indent character or characters. Four spaces are used because that is
89+ the recommendation of PEP 8.
90+
91+ Default: ` ` (four spaces)
92+
93+
5694#### <a name =" commentPrefix " ></a >commentPrefix
95+
96+ Prefix character or characters for comments. The hash+space is recommended by
97+ PEP 8.
98+
99+ Default: ` # ` (hash + space)
100+
101+
57102#### <a name =" expressionVariableNamingHandler " ></a >expressionVariableNamingHandler
58103
104+ When the compiler needs to make up a variable name (for example, to emulate
105+ assignment expressions), it calls this handler to produce a new one.
106+
107+ Default: ` basic.globalNameCounter `
108+
109+
59110#### <a name =" modulePrologueHandlers " ></a >modulePrologueHandlers
111+
112+ These values are strings or generators that yield strings for a module
113+ prologue.
114+
115+ Default: ` [basic.shebangLine, basic.simpleDocString, basic.maybeBsr, basic.maybeSyncHelpers] `
116+
117+
60118#### <a name =" moduleEpilogueHandlers " ></a >moduleEpilogueHandlers
119+
120+ These generators yield lines for a module epilogue.
121+
122+ Default: ` [basic.scriptMainStanza] `
123+
124+
61125#### <a name =" moduleOutputHandlers " ></a >moduleOutputHandlers
126+
127+ These generators yield (possibly modified) source strings for a module.
128+
129+ Default: ` [basic.outputSubs] `
130+
131+
62132#### <a name =" modulePackageDeclarationHandler " ></a >modulePackageDeclarationHandler
133+
134+ This config item is called to handle package declarations. The default handler simply
135+ turns those declarations into comments.
136+
137+ Default: ` basic.commentedPackages `
138+
139+
63140#### <a name =" moduleImportDeclarationHandler " ></a >moduleImportDeclarationHandler
141+
142+ This config item is called to handle import statements. The default handler
143+ transforms the import statements into Python imports.
144+
145+ Default: ` basic.simpleImports `
146+
147+
64148#### <a name =" moduleOutputSubs " ></a >moduleOutputSubs
65149
150+ Mapping of input/output regular expressions used during the final pass of
151+ source generation.
152+
153+ Default: refer to the [ java2python.config.default] [ 1 ] module.
154+
66155
67156#### <a name =" classHeadHandlers " ></a >classHeadHandlers
157+
158+ These generators yield doc values for the head of classes.
159+
160+ Default: ` [basic.simpleDocString] `
161+
162+
68163#### <a name =" classBaseHandlers " ></a >classBaseHandlers
164+
165+ These generators yield the base types (as strings) for classes.
166+
167+ Default: ` [basic.defaultBases] `
168+
169+
69170#### <a name =" classPostWalkHandlers " ></a >classPostWalkHandlers
70171
172+ These handlers are called with each class object after it has been completely
173+ constructed.
174+
175+ Default: ` [] `
176+
177+
71178#### <a name =" interfaceBaseHandlers " ></a >interfaceBaseHandlers
179+
180+ These generators yield the base types (as strings) for interfaces.
181+
182+ Default: ` [basic.defaultBases] `
183+
184+
72185#### <a name =" interfaceHeadHandlers " ></a >interfaceHeadHandlers
73186
187+ These generators yield doc values for the head of interfaces.
188+
189+ Default: ` [basic.simpleDocString, '__metaclass__ = ABCMeta'] `
190+
191+
74192#### <a name =" enumHeadHandlers " ></a >enumHeadHandlers
193+
194+ These generators yield doc values for the head of enums.
195+
196+ Default: ` [basic.simpleDocString] `
197+
198+
75199#### <a name =" enumValueHandler " ></a >enumValueHandler
76200
201+ This handler is responsible for creating enum values on enum classes after
202+ they've been defined.
203+
204+ Default: ` basic.enumConstStrings `
205+
77206
78207#### <a name =" methodParamHandlers " ></a >methodParamHandlers
208+
209+ This handler is responsible for constructing method parameters.
210+
211+ Default: ` basic.defaultParams `
212+
213+
79214#### <a name =" methodLockFunctionName " ></a >methodLockFunctionName
215+
216+ This is the name of the callable used to construct locks for an object with the
217+ synchronized keyword.
218+
219+ Default: ` 'lock_for_object' `
220+
221+
80222#### <a name =" methodHeadHandlers " ></a >methodHeadHandlers
223+
224+ These generators yield values for the head of classes.
225+
226+ Default: ` [basic.simpleDocString] `
227+
228+
81229#### <a name =" methodPrologueHandlers " ></a >methodPrologueHandlers
82230
231+ These generators yield values for the module prologue.
232+
233+ Default:
234+ ```[ basic.maybeAbstractMethod,
235+ basic.maybeClassMethod,
236+ basic.maybeSynchronizedMethod,
237+ basic.overloadedClassMethods,
238+ ]
239+ ```
240+
83241#### <a name =" astTransforms " ></a >astTransforms
242+
243+ The AST transformer uses these declarations to modify an AST before compiling
244+ it to Python source.
245+
246+ Default: refer to the [ java2python.config.default] [ 1 ] module.
247+
84248#### <a name =" typeSubs " ></a >typeSubs
85249
250+ Many Java identifiers have a 1:1 relationship with Python identifiers, and this
251+ mapping is used to convert them when found. Note that this mapping is now
252+ unnecessary and will be folded into the ` astTransforms ` sequence in future
253+ releases.
86254
87255[ usage ] : https://github.com/natural/java2python/tree/master/doc/usage.md
88256[ 1 ] : https://github.com/natural/java2python/blob/master/java2python/config/default.py
0 commit comments