11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
3- """ java2python.compiler.template -> Base classes for writing Python source. """
4- ##
5- # This module defines templates -- blocks of Python source code --
6- # that can be easily manipulated and written. Each base provides
3+ # java2python.compiler.template -> Base classes for writing Python source.
4+ #
5+ # This module defines templates -- chunks of Python source code --
6+ # that can be easily manipulated and written. Each class provides
77# string methods (__str__, dump, dumps) for serializing instances as a
8- # source code string. The base types also provide many utility
9- # methods.
8+ # source code string.
109#
1110# The Factory class is used to to provide runtime lookup of concrete
1211# classes; this was necessary to accommodate splitting the behavior of
2524class Factory (object ):
2625 """ Factory -> creates pre-configured callables for new block instances.
2726
28- The templates use an instance of this class as a quick and simple
29- interface to create new templates like this:
27+ Both templates and visitors use an instance of this class as a simple
28+ interface to create new blocks like this:
3029
3130 stat = self.factory.statement()
3231
3332 The `__getattr__` method does the work of looking up and returning
34- the appropriate template class. The lookup depends on the types
33+ the appropriate block class. The lookup depends on the types
3534 registry, which is populated by the FactoryTypeDetector metaclass
3635 below.
3736
38- The important thing to realize regarding this factory is this:
37+ One important thing to realize regarding this factory is this:
3938 when an attribute is requested (`self.factory.expr` for example),
4039 the factory locates the type and returns a constructor for it with
4140 the config object pre-applied.
@@ -57,19 +56,20 @@ class FactoryTypeDetector(type):
5756 """ FactoryTypeDetector -> detects factory-creatable types as they are defined.
5857
5958 As subclasses are created they are checked for an attribute called
60- `factoryTypeName `. If present, that key is used to populate the
61- factory type registry above .
62-
63- Note that the actual subclasses are not created here (none of
64- these specify a `factoryTypeName `). Actual factory types are
65- created in `java2python.compiler.block`. This is because we're
66- after not templates , but visitors combined with templates, aka
67- blocks. Refer to the `blocks` module for the specific factory
59+ `factoryName `. If present, that key is used to populate the
60+ type registry in the Factory class .
61+
62+ Note that the actual subclasses are not created here (templates and
63+ visitors do not specify a `factoryName `). Actual factory types are created
64+ in `java2python.compiler.block`. This is because we're after not
65+ templates or visitors , but rather visitors combined with templates ( aka
66+ blocks) . Refer to the `blocks` module for the specific factory
6867 type names.
68+
6969 """
7070 def __init__ (cls , name , bases , namespace ):
7171 try :
72- Factory .types [cls .factoryTypeName ] = cls
72+ Factory .types [cls .factoryName ] = cls
7373 except (AttributeError , ):
7474 pass
7575
@@ -95,7 +95,7 @@ class Base(object):
9595 * Configuration
9696
9797 This class provides utility methods for retrieving values from the
98- run-time configuration. See the definition of `configHandler` and
98+ runtime configuration. See the definition of `configHandler` and
9999 `configHandlers` for details.
100100
101101 * Serialization
@@ -292,9 +292,8 @@ def wrapper(*a, **b):
292292
293293
294294class Expression (Base ):
295- """ Expression -> formatting for Python expressions.
295+ """ Expression -> formatting for Python expressions. """
296296
297- """
298297 isExpression = True
299298
300299 def __init__ (self , config , left = '' , right = '' , fs = FS .lr , parent = None , tail = '' ):
@@ -342,9 +341,8 @@ def isComment(self):
342341
343342
344343class Comment (Expression ):
345- """ Comment -> formatting for Python comments.
344+ """ Comment -> formatting for Python comments. """
346345
347- """
348346 isComment = True
349347
350348 def __repr__ (self ):
@@ -356,9 +354,8 @@ def __repr__(self):
356354
357355
358356class Statement (Base ):
359- """ Statement -> formatting for Python statements.
357+ """ Statement -> formatting for Python statements. """
360358
361- """
362359 isStatement = True
363360
364361 def __init__ (self , config , keyword , fs = FS .lr , parent = None ):
@@ -378,9 +375,7 @@ def iterPrologue(self):
378375
379376
380377class Module (Base ):
381- """ Module -> formatting for Python modules.
382-
383- """
378+ """ Module -> formatting for Python modules. """
384379 isModule = True
385380
386381 def iterBody (self ):
@@ -405,9 +400,7 @@ def iterPrologue(self):
405400
406401
407402class Class (ClassMethodSharedMixin , Base ):
408- """ Class -> formatting for Python classes.
409-
410- """
403+ """ Class -> formatting for Python classes. """
411404 isClass = True
412405
413406 def iterBases (self ):
@@ -444,26 +437,20 @@ def sprinkleBlanks(body):
444437
445438
446439class Annotation (Class ):
447- """ Annotation -> formatting for annotations converted to Python classes.
448-
449- """
440+ """ Annotation -> formatting for annotations converted to Python classes. """
450441 isAnnotation = True
451442
452443 def __init__ (self , config , name = None , type = None , parent = None ):
453444 super (Annotation , self ).__init__ (config , name , type , parent )
454445
455446
456447class Enum (Class ):
457- """ Enum -> formatting for enums converted to Python classes.
458-
459- """
448+ """ Enum -> formatting for enums converted to Python classes. """
460449 isEnum = True
461450
462451
463452class Interface (Class ):
464- """ Interface -> formatting for interfaces converted to Python classes.
465-
466- """
453+ """ Interface -> formatting for interfaces converted to Python classes. """
467454 isInterface = True
468455
469456
@@ -472,9 +459,7 @@ class MethodContent(Base):
472459
473460
474461class Method (ClassMethodSharedMixin , Base ):
475- """ Method -> formatting for Python methods.
476-
477- """
462+ """ Method -> formatting for Python methods. """
478463 isMethod = True
479464
480465 def __init__ (self , config , name = None , type = None , parent = None ):
0 commit comments