javaclass

Changeset

178:3b3b9f5e2793
2005-02-21 Paul Boddie raw files shortlog changelog graph Attempted to add more sophisticated circular import handling.
javaclass/classhook.py (file)
     1.1 --- a/javaclass/classhook.py	Mon Feb 21 00:17:51 2005 +0100
     1.2 +++ b/javaclass/classhook.py	Mon Feb 21 00:17:51 2005 +0100
     1.3 @@ -313,7 +313,7 @@
     1.4  
     1.5          # Return modules used by external names.
     1.6  
     1.7 -        external_module_names = self._get_external_module_names(external_names)
     1.8 +        external_module_names = self._get_external_module_names(external_names, name)
     1.9  
    1.10          # Repeatedly load classes from referenced modules.
    1.11  
    1.12 @@ -323,10 +323,26 @@
    1.13  
    1.14          return module
    1.15  
    1.16 -    def _get_external_module_names(self, names):
    1.17 +    def _get_external_module_names(self, names, current_module_name):
    1.18          groups = self._get_names_grouped_by_module(names)
    1.19          if groups.has_key(""):
    1.20              del groups[""]
    1.21 +
    1.22 +        # NOTE: Could filter out the current module and all parent modules.
    1.23 +        # NOTE:
    1.24 +        # NOTE: current_module_parts = current_module_name.split(".")
    1.25 +        # NOTE: while len(current_module_parts) > 0:
    1.26 +        # NOTE:     try:
    1.27 +        # NOTE:         del groups[".".join(current_module_parts)]
    1.28 +        # NOTE:     except KeyError:
    1.29 +        # NOTE:         pass
    1.30 +        # NOTE:     del current_module_parts[-1]
    1.31 +
    1.32 +        try:
    1.33 +            del groups[".".join(current_module_name)]
    1.34 +        except KeyError:
    1.35 +            pass
    1.36 +
    1.37          return groups.keys()
    1.38  
    1.39      def _get_names_grouped_by_module(self, names):
    1.40 @@ -367,19 +383,24 @@
    1.41  
    1.42          # Create the classes.
    1.43  
    1.44 -        real_classes = []
    1.45 +        real_classes = {}
    1.46 +        real_classes_index = []
    1.47          for class_name in init_order:
    1.48              try:
    1.49                  module, translator = self.loaded_classes[class_name]
    1.50                  global_names = module.__dict__
    1.51 -                real_classes.append((module, translator.get_class(global_names)))
    1.52 +                if not real_classes.has_key(module):
    1.53 +                    real_classes[module] = []
    1.54 +                real_class = translator.get_class(global_names, real_classes)
    1.55 +                real_classes[class_name].append(real_class)
    1.56 +                real_classes_index.append((module, real_class))
    1.57              except KeyError:
    1.58                  # NOTE: Should be a non-Java class.
    1.59                  pass
    1.60  
    1.61          # Finally, call __clinit__ methods for all relevant classes.
    1.62  
    1.63 -        for module, cls in real_classes:
    1.64 +        for module, cls in real_classes_index:
    1.65              if hasattr(cls, "__clinit__"):
    1.66                  global_names = module.__dict__
    1.67                  eval(cls.__clinit__.func_code, global_names)