javaclass

Changeset

52:4cf5981fa430
2004-11-14 Paul Boddie raw files shortlog changelog graph Added Java package and class data types and attempted to fix package/module importing even further.
classhook.py (file)
     1.1 --- a/classhook.py	Sun Nov 14 02:37:27 2004 +0100
     1.2 +++ b/classhook.py	Sun Nov 14 02:38:25 2004 +0100
     1.3 @@ -6,7 +6,9 @@
     1.4  import classfile, bytecode
     1.5  import new
     1.6  
     1.7 -"""
     1.8 +JAVA_PACKAGE = 20041113
     1.9 +JAVA_CLASS = 20041114
    1.10 +
    1.11  class ClassHooks(ihooks.Hooks):
    1.12  
    1.13      "A filesystem hooks class providing information about supported files."
    1.14 @@ -15,19 +17,12 @@
    1.15  
    1.16          "Return the recognised suffixes."
    1.17  
    1.18 -        return ihooks.Hooks.get_suffixes(self) + [(os.extsep + "class", "r", PY_SOURCE)]
    1.19 -"""
    1.20 +        return ihooks.Hooks.get_suffixes(self) + [("", "", JAVA_PACKAGE), (os.extsep + "class", "r", JAVA_CLASS)]
    1.21  
    1.22  class ClassLoader(ihooks.ModuleLoader):
    1.23  
    1.24      "A class providing support for searching directories for supported files."
    1.25  
    1.26 -    """
    1.27 -    def find_module(self, name, path=None):
    1.28 -        print "find_module", name, path
    1.29 -        return ihooks.ModuleLoader.find_module(self, name, path)
    1.30 -    """
    1.31 -
    1.32      def find_module_in_dir(self, name, dir, allow_packages=1):
    1.33  
    1.34          """
    1.35 @@ -50,10 +45,10 @@
    1.36          else:
    1.37              path = os.path.join(dir, name)
    1.38  
    1.39 -        print "Processing name", name, "in", dir, "producing", path
    1.40 +        #print "Processing name", name, "in", dir, "producing", path
    1.41  
    1.42          if self._find_module_at_path(path):
    1.43 -            return (None, path, ("", "", PKG_DIRECTORY))
    1.44 +            return (None, path, ("", "", JAVA_PACKAGE))
    1.45          else:
    1.46              return None
    1.47  
    1.48 @@ -84,13 +79,12 @@
    1.49          problem occurred in the import operation.
    1.50          """
    1.51  
    1.52 -        #result = ihooks.ModuleLoader.load_module(self, name, stuff)
    1.53 -        #if result is not None:
    1.54 -        #    return result
    1.55 -
    1.56          # Just go into the directory and find the class files.
    1.57  
    1.58          file, filename, info = stuff
    1.59 +        suffix, mode, datatype = info
    1.60 +        if datatype != JAVA_PACKAGE:
    1.61 +            return ihooks.ModuleLoader.load_module(self, name, stuff)
    1.62  
    1.63          print "Loading", file, filename, info
    1.64  
    1.65 @@ -116,26 +110,7 @@
    1.66          module.__path__ = [filename]
    1.67          return module
    1.68  
    1.69 -"""
    1.70 -class ClassImporter(ihooks.ModuleImporter):
    1.71 -
    1.72 -    def find_head_package(self, parent, name):
    1.73 -        print "find_head_package", parent, name
    1.74 -        return ihooks.ModuleImporter.find_head_package(self, parent, name)
    1.75 -
    1.76 -    def import_it(self, partname, fqname, parent, force_load=0):
    1.77 -        print "import_it", partname, fqname, parent, force_load
    1.78 -        print "modules", self.modules
    1.79 -        try:
    1.80 -            return parent.__dict__[partname]
    1.81 -
    1.82 -        except (KeyError, AttributeError):
    1.83 -            return ihooks.ModuleImporter.import_it(
    1.84 -                self, partname, fqname, parent, force_load
    1.85 -                )
    1.86 -"""
    1.87 -
    1.88 -importer = ihooks.ModuleImporter(loader=ClassLoader(hooks=ihooks.Hooks()))
    1.89 +importer = ihooks.ModuleImporter(loader=ClassLoader(hooks=ClassHooks()))
    1.90  importer.install()
    1.91  
    1.92  # vim: tabstop=4 expandtab shiftwidth=4