def add_class_or_module(collection, class_type, name, superclass)
      cls = collection[name]

      if cls then
        cls.superclass = superclass unless cls.module?
        puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC
      else
        if class_type == NormalModule then
          all = @@all_modules
        else
          all = @@all_classes
        end

        cls = all[name]

        if !cls then
          cls = class_type.new name, superclass
          all[name] = cls unless @done_documenting
        else
          # If the class has been encountered already, check that its
          # superclass has been set (it may not have been, depending on
          # the context in which it was encountered).
          if class_type == NormalClass
            if !cls.superclass then
              cls.superclass = superclass
            end
          end
        end

        collection[name] = cls unless @done_documenting

        cls.parent = self
      end

      cls
    end
def add_class_or_module(collection, class_type, name, superclass)
      cls = collection[name]

      if cls then
        cls.superclass = superclass unless cls.module?
        puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC
      else
        if class_type == NormalModule then
          all = @@all_modules
        else
          all = @@all_classes
        end

        cls = all[name]

        if !cls then
          cls = class_type.new name, superclass
          all[name] = cls unless @done_documenting
        else
          # If the class has been encountered already, check that its
          # superclass has been set (it may not have been, depending on
          # the context in which it was encountered).
          if class_type == NormalClass
            if !cls.superclass then
              cls.superclass = superclass
            end
          end
        end

        collection[name] = cls unless @done_documenting

        cls.parent = self
      end

      cls
    end
Adding a class or module to a TopLevel is special, as we only want one
 copy of a particular top-level class. For example, if both file A and
 file B implement class C, we only want one ClassModule object for C.
 This code arranges to share classes and modules between files.