class RDoc::Context

def add_class_or_module(collection, class_type, name, superclass = nil)

def add_class_or_module(collection, class_type, name, superclass = nil)
  full_name = child_name name
  mod = collection[name]
  if mod then
    mod.superclass = superclass unless mod.module?
  else
    all = if class_type == RDoc::NormalModule then
            RDoc::TopLevel.modules_hash
          else
            RDoc::TopLevel.classes_hash
          end
    mod = all[full_name]
    unless mod then
      mod = class_type.new name, superclass
    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 == RDoc::NormalClass then
        mod.superclass = superclass unless mod.superclass
      end
    end
    unless @done_documenting then
      all[full_name] = mod
      collection[name] = mod
    end
    mod.section = @current_section
    mod.parent = self
  end
  mod
end