forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.py
More file actions
38 lines (33 loc) · 1.38 KB
/
block.py
File metadata and controls
38 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# java2python.compiler.block -> Visitors combined with templates.
#
# This module defines classes which combine AST walking with source
# generation. We've put these two behaviors into separate modules,
# java2python.compiler.template for creating source code, and
# java2python.compiler.visitor for walking ANTLR trees.
#
# Each of the classes depends on the behavior of its counterpart.
# This means they're very tightly coupled and that the classes are not
# very reusable. The module split does allow for grouping of related
# methods and does hide the cluttered code.
from sys import modules
from java2python.compiler import template, visitor
def addTypeToModule((className, factoryName)):
""" Constructs and adds a new type to this module. """
bases = (getattr(template, className), getattr(visitor, className))
newType = type(className, bases, dict(factoryName=factoryName))
setattr(modules[__name__], className, newType)
map(addTypeToModule, (
('Annotation', 'at'),
('Class', 'klass'),
('Comment', 'comment'),
('Enum', 'enum'),
('Expression', 'expr'),
('Interface', 'interface'),
('Method', 'method'),
('MethodContent', 'methodContent'),
('Module', 'module'),
('Statement', 'statement'),
)
)