Skip to content

Commit e826511

Browse files
author
Troy Melhase
committed
More abs urls.
1 parent 4301155 commit e826511

File tree

4 files changed

+174
-143
lines changed

4 files changed

+174
-143
lines changed

doc/customization.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
.. _customization:
1+
## java2python Customization
22

3-
Customization
4-
=============
3+
### Basic
54

6-
Basic Customization
7-
-------------------
8-
basic and advanced... wouldn't it be great?
9-
10-
11-
Advanced or Not-So-Basic Customization
12-
--------------------------------------
13-
14-
There are two ways to further customize the behavior of |j2py|.
15-
16-
17-
Advanced Advanced but It's-Still-Not-Hard Customization
18-
-------------------------------------------------------
19-
20-
Truly?
5+
### Advanced

doc/features.md

Lines changed: 117 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# Translation Features
1+
## Translation Features
22

3-
The java2python package can translate any syntactically valid Java source
4-
code file. The generated Python code is not guaranteed to run, nor is
5-
guaranteed to be syntactically valid Python. However, java2python works
6-
well many cases, and in some of those, it creates perfectly usable and
7-
workable Python code.
3+
The java2python package can translate any syntactically valid Java source code
4+
file. The generated Python code is not guaranteed to run, nor is guaranteed to
5+
be syntactically valid Python. However, java2python works well many cases, and
6+
in some of those, it creates perfectly usable and workable Python code.
87

98

10-
## General Approach
9+
### General Approach
1110

1211
The approach taken by java2python is to favor readability over correctness.
1312

14-
## Identifiers and Qualified Identifiers
13+
### Identifiers and Qualified Identifiers
1514

16-
java2python copies identifiers from source to target, modifying the value only when:
15+
java2python copies identifiers from source to target, modifying the value only
16+
when:
1717

1818
* the identifier conflicts with a Python keyword or builtin, or
1919
* the identifier has an explicit lexical transformation
2020

2121

22-
## Literals: Integer, Floating Point, Character, String, Boolean and Null
22+
### Literals: Integer, Floating Point, Character, String, Boolean and Null
2323

2424
Literals are copied from source to target with the following modifications:
2525

@@ -32,34 +32,41 @@ Literals are copied from source to target with the following modifications:
3232
Transformation of literal values happens at the AST level; see the
3333
`astTransforms` configuration value for details.
3434

35-
## Expressions
35+
### Expressions
3636

37-
### Constant Expression
37+
#### Constant Expression
3838

3939
Constant expressions are translated to their Python equivalents.
4040

41-
### Ternary Expressions
41+
#### Ternary Expressions
4242

43-
Ternary expressions are translated to their Python form (`val if condition else other`)
43+
Ternary expressions are translated to their Python form (`val if condition else
44+
other`)
4445

4546

46-
## Prefix Operators
47+
### Prefix Operators
4748

4849
All of the Java prefix operators are supported:
4950

5051
++ -- ! ~ + -
5152

52-
In the case of `++` and `--`, java2python translates to `+= 1` and `-= 1`. If necessary, those expressions are moved outside of statements.
53+
In the case of `++` and `--`, java2python translates to `+= 1` and `-= 1`. If
54+
necessary, those expressions are moved outside of statements.
5355

54-
## Assignment Operators
56+
### Assignment Operators
5557

56-
All of the following assignment operators are translated into their Python equivalents:
58+
All of the following assignment operators are translated into their Python
59+
equivalents:
5760

5861
= += -= *= /= &= |= ^= %= <<= >>=
5962

60-
The bit shift right (`>>>`)and bit shift assign right (`>>>=`) operators are mapped to a function; if java2python detects code that uses either of these, it replaces the operator with that function and includes the function within the output. This behavior is controlled by the `modulePrologueHandlers` config handler.
63+
The bit shift right (`>>>`)and bit shift assign right (`>>>=`) operators are
64+
mapped to a function; if java2python detects code that uses either of these, it
65+
replaces the operator with that function and includes the function within the
66+
output. This behavior is controlled by the `modulePrologueHandlers` config
67+
handler.
6168

62-
## Infix Operators
69+
### Infix Operators
6370

6471
The following operators are translated to their Python equivalents:
6572

@@ -68,7 +75,7 @@ The following operators are translated to their Python equivalents:
6875

6976
Refer to the note above regarding bit shift right.
7077

71-
## Basic Types
78+
### Basic Types
7279

7380
The basic Java types are mapped to Python types as follows:
7481

@@ -77,125 +84,161 @@ The basic Java types are mapped to Python types as follows:
7784
* `float` and `double` become `float`
7885
* `boolean` becomes `bool`
7986

80-
### Arrays
87+
#### Arrays
8188

82-
Java arrays and array access expressions are translated to their Python equivalents.
89+
Java arrays and array access expressions are translated to their Python
90+
equivalents.
8391

8492

85-
## Types, Interfaces, Enums
93+
### Types, Interfaces, Enums
8694

8795
Java classes, interfaces, and enums are translated into Python classes.
8896

8997
In the case of interfaces, the strategy is configurable. By default,
90-
interfaces are translated to classes utilizing the `ABCMeta` class. The package
91-
includes config handlers that can translate to simple classes (inheriting from
92-
`object`), or from Zope Interfaces. Interface base types are controlled via the `interfaceBaseHandlers` config item. The `interfaceHeadHandlers` config item controls the
93-
metaclass.
98+
interfaces are translated to classes utilizing the `ABCMeta` class. The
99+
package includes config handlers that can translate to simple classes
100+
(inheriting from `object`), or from Zope Interfaces. Interface base types are
101+
controlled via the `interfaceBaseHandlers` config item. The
102+
`interfaceHeadHandlers` config item controls the metaclass.
94103

95104
Enums are also translated via a configurable strategy. By default, enumerated
96105
values are created as class attributes with string values. The package
97-
includes a config handler to create class attributes with integer values. The config handler
98-
that controls enumeration value construction is `enumValueHandler`.
106+
includes a config handler to create class attributes with integer values. The
107+
config handler that controls enumeration value construction is
108+
`enumValueHandler`.
99109

100110

101-
## Statements
111+
### Statements
102112

103-
### assert
104-
Java `assert` statements are translated to equivalent Python `assert` statements.
113+
#### assert
114+
115+
Java `assert` statements are translated to equivalent Python `assert`
116+
statements.
117+
118+
#### if
105119

106-
### if
107120
Java `if` statements are translated to equivalent Python `if` statements.
108121

109122

110-
### for
123+
#### for
124+
111125
Java `for` statements are translated to equivalent Python `for` statements.
112126

113-
### while and do
114-
Java `while` and `do` statements are translated to equivalent Python `while` statements.
127+
#### while and do
128+
129+
Java `while` and `do` statements are translated to equivalent Python `while`
130+
statements.
131+
132+
#### try and catch
115133

116-
### try and catch
117-
Java `try` and `catch` statements are translated to equivalent Python `try` and `except` statements.
134+
Java `try` and `catch` statements are translated to equivalent Python `try` and
135+
`except` statements.
118136

119-
### switch and case
120-
Java `switch` and `case` statements are translated to equivalent Python `if` statements.
137+
#### switch and case
121138

122-
### synchronized
139+
Java `switch` and `case` statements are translated to equivalent Python `if`
140+
statements.
123141

124-
In the case of a `synchronized` method or static method, the compiler will include a decorator, `@synchronized` in
125-
the method or static method preamble. In the case of a `synchronized` block, the compiler will translate to this form:
142+
#### synchronized
143+
144+
In the case of a `synchronized` method or static method, the compiler will
145+
include a decorator, `@synchronized` in the method or static method preamble.
146+
In the case of a `synchronized` block, the compiler will translate to this
147+
form:
126148

127149
with lock_for_object(expr):
128150
...
129151

130-
The `lock_for_object` callable is the default and can be controlled via the `methodLockFunctionName` config item.
131-
Also of note, the default `modulePrologueHandlers` uses a generator named `maybeSyncHelpers` to include
152+
The `lock_for_object` callable is the default and can be controlled via the
153+
`methodLockFunctionName` config item. Also of note, the default
154+
`modulePrologueHandlers` uses a generator named `maybeSyncHelpers` to include
132155
Python helper code for synchronization.
133156

134-
### return
135-
Java `return` statements are translated to equivalent Python `return` statements.
157+
#### return
158+
159+
Java `return` statements are translated to equivalent Python `return`
160+
statements.
161+
136162

163+
#### throw
137164

138-
### throw
139165
Java `throw` statements are translated to equivalent Python `throw` statements.
140166

141-
### break
142-
Java `break` statements are translated to equivalent Python `break` statements. However, a Java `break` statement with an identifier (e.g., `break FOO`) is not supported. If the compiler detects such a statement, a warning will be printed and the translated source will not
143-
contain the original label.
167+
#### break
168+
169+
Java `break` statements are translated to equivalent Python `break` statements.
170+
However, a Java `break` statement with an identifier (e.g., `break FOO`) is not
171+
supported. If the compiler detects such a statement, a warning will be printed
172+
and the translated source will not contain the original label.
173+
174+
#### continue
144175

145-
### continue
146-
Java `continue` statements are translated to equivalent Python `continue` statements. However, a Java `continue` statement with an identifier (e.g., `continue FOO`) is not supported. If the compiler detects such a statement, a warning will be printed and the translated source will not
147-
contain the original label.
176+
Java `continue` statements are translated to equivalent Python `continue`
177+
statements. However, a Java `continue` statement with an identifier (e.g.,
178+
`continue FOO`) is not supported. If the compiler detects such a statement, a
179+
warning will be printed and the translated source will not contain the original
180+
label.
148181

149182

150-
## Other Keywords
183+
### Other Keywords
151184

152-
### this
185+
#### this
153186

154187
The `this` Java keyword is translated to the Python pseudo keyword `self`.
155188

156-
### instanceof
189+
#### instanceof
157190

158-
The `instance of` Java keyword is translated to the `isinstance(…)` Python function call.
191+
The `instance of` Java keyword is translated to the `isinstance(…)` Python
192+
function call.
159193

160-
### super
194+
#### super
161195

162196
The Java keyword `super` is translated to the `super(…)` Python function call.
163197

164-
### .class
198+
#### .class
165199

166-
The compiler translates Java `.class` expressions to `.__class__` attribute references.
200+
The compiler translates Java `.class` expressions to `.__class__` attribute
201+
references.
167202

168-
### void
203+
#### void
169204

170-
The Java keyword `void` is typically discarded by the compiler. In the case of the `void.class` form, the compiler translates the expression to `None.__class__`.
205+
The Java keyword `void` is typically discarded by the compiler. In the case of
206+
the `void.class` form, the compiler translates the expression to
207+
`None.__class__`.
171208

172209

173-
## Annotations
210+
### Annotations
174211

175-
Annotations are typically dropped by the compiler. The following Java annotations have little or no meaning in Python, and are discarded:
212+
Annotations are typically dropped by the compiler. The following Java
213+
annotations have little or no meaning in Python, and are discarded:
176214

177215
public protected private abstract final native transient
178216
volatile strictfp
179217

180-
### static
218+
#### static
181219

182-
The `static` method keyword is translated to a `@classmethod` decorator for the corresponding method.
220+
The `static` annotation is translated to a `@classmethod` decorator for the
221+
corresponding method.
183222

184-
### synchronized
223+
#### synchronized
185224

186-
When used as a method or static method annotation, the `synchronized` keyword is translated to a `@synchronized` method decorator. This behavior is controllable via the `methodPrologueHandlers` config item.
225+
When used as a method or static method annotation, the `synchronized` keyword
226+
is translated to a `@synchronized` method decorator. This behavior is
227+
controllable via the `methodPrologueHandlers` config item.
187228

188229
See the note above regarding the use of `synchronized` within blocks.
189230

190-
## Comments
231+
### Comments
191232

192-
Both Java end-of-line comments and multi-line comments are translated to Python comments. The comment prefix is `# ` by default, and is controllable via the `commentPrefix` config item.
233+
Both Java end-of-line comments and multi-line comments are translated to Python
234+
comments. The comment prefix is `# ` (hash plus space) by default, and is
235+
controllable via the `commentPrefix` config item.
193236

194-
### JavaDoc
237+
#### JavaDoc
195238

196239
JavaDoc comments are preserved as Python comments.
197240

198241

199-
## References
242+
### References
200243

201244
* Java language specification: http://java.sun.com/docs/books/jls/third_edition/html/syntax.html

0 commit comments

Comments
 (0)