# File lib/rdoc/ri/driver.rb, line 509
  def class_document name, found, klasses, includes
    also_in = []

    out = RDoc::Markup::Document.new

    add_class out, name, klasses

    add_includes out, includes

    found.each do |store, klass|
      comment = klass.comment
      # TODO the store's cache should always return an empty Array
      class_methods    = store.class_methods[klass.full_name]    || []
      instance_methods = store.instance_methods[klass.full_name] || []
      attributes       = store.attributes[klass.full_name]       || []

      if comment.empty? and
         instance_methods.empty? and class_methods.empty? then
        also_in << store
        next
      end

      add_from out, store

      unless comment.empty? then
        out << RDoc::Markup::Rule.new(1)

        if comment.merged? then
          parts = comment.parts
          parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length
          parts.flatten!
          parts.pop

          out.push(*parts)
        else
          out << comment
        end
      end

      if class_methods or instance_methods or not klass.constants.empty? then
        out << RDoc::Markup::Rule.new(1)
      end

      unless klass.constants.empty? then
        out << RDoc::Markup::Heading.new(1, "Constants:")
        out << RDoc::Markup::BlankLine.new
        list = RDoc::Markup::List.new :NOTE

        constants = klass.constants.sort_by { |constant| constant.name }

        list.push(*constants.map do |constant|
          parts = constant.comment.parts if constant.comment
          parts << RDoc::Markup::Paragraph.new('[not documented]') if
            parts.empty?

          RDoc::Markup::ListItem.new(constant.name, *parts)
        end)

        out << list
        out << RDoc::Markup::BlankLine.new
      end

      add_method_list out, class_methods,    'Class methods'
      add_method_list out, instance_methods, 'Instance methods'
      add_method_list out, attributes,       'Attributes'
    end

    add_also_in out, also_in

    out
  end