Skip to content

Latest commit

 

History

History
88 lines (58 loc) · 3.4 KB

customization.md

File metadata and controls

88 lines (58 loc) · 3.4 KB

Customization

The java2python compiler defers a significant amount of its processing to handlers defined within configuration files. These configuration files, directories, and modules are supplied to the j2py script on the command line. See the usage page for instructions on specifying additional configs.

The default configuration module is java2python.config.default. Refer to the source of that module for its values and additional descriptions.

Usage

To change the behavior of some or all of the config items, create a Python file, define the items you want, and specify that file when invoking j2py.

For example, if you would like to change the comment prefix to ##, you might do this:

$ echo "indentPrefix = '##'" >> myconfig.py

Then run the script:

$ j2py SomeJavaSource.java -c myconfig.py 

The config files are Python modules, so you can use the full power of Python when writing your configurations.

A Note About Some of the Names: Prologue, Base, Head, and Epilogue

When a config point has Prologue in its name, it means that the item will be responsible for generating code before the output. For example, method prologue handlers generate decorators, while module prologue handlers generate the shebang line.

When a config point has Base in the name, it means that the item will be responsible for generating the base classes of a class, enum, or interface.

A config point with Head in the name means that the item will be responsible for generating code for the section between the declaration and the body of the item. For example:

class X(object):
    """ this is a comment generated by classHeadHandlers """

Finally, when a config point contains Epilogue, it means that the item will be responsible for generating code after the body of the item. The only recognized epilogue config point is moduleEpilogueHandlers, which generates a main script stanza if necessary.

Customization Points

indentPrefix

commentPrefix

expressionVariableNamingHandler

modulePrologueHandlers

moduleEpilogueHandlers

moduleOutputHandlers

modulePackageDeclarationHandler

moduleImportDeclarationHandler

moduleOutputSubs

classHeadHandlers

classBaseHandlers

classPostWalkHandlers

interfaceBaseHandlers

interfaceHeadHandlers

enumHeadHandlers

enumValueHandler

methodParamHandlers

methodLockFunctionName

methodHeadHandlers

methodPrologueHandlers

astTransforms

typeSubs