[前][次][番号順一覧][スレッド一覧]

ruby-changes:20257

From: drbrain <ko1@a...>
Date: Thu, 30 Jun 2011 06:18:12 +0900 (JST)
Subject: [ruby-changes:20257] drbrain:r32305 (trunk): * lib/rdoc: Update to RDoc 3.8 which contains fixes for documentation

drbrain	2011-06-30 06:17:31 +0900 (Thu, 30 Jun 2011)

  New Revision: 32305

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32305

  Log:
    * lib/rdoc:  Update to RDoc 3.8 which contains fixes for documentation
      in trunk.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/rdoc/class_module.rb
    trunk/lib/rdoc/known_classes.rb
    trunk/lib/rdoc/parser/c.rb
    trunk/lib/rdoc/parser/ruby.rb
    trunk/lib/rdoc/ri/store.rb
    trunk/lib/rdoc/top_level.rb
    trunk/lib/rdoc.rb
    trunk/test/rdoc/test_rdoc_class_module.rb
    trunk/test/rdoc/test_rdoc_parser_ruby.rb
    trunk/test/rdoc/test_rdoc_ri_store.rb
    trunk/test/rdoc/test_rdoc_top_level.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32304)
+++ ChangeLog	(revision 32305)
@@ -1,3 +1,8 @@
+Thu Jun 30 06:16:53 2011  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc:  Update to RDoc 3.8 which contains fixes for documentation
+	  in trunk.
+
 Thu Jun 30 02:53:26 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* thread.c (rb_threadptr_execute_interrupts_common): remove
Index: lib/rdoc.rb
===================================================================
--- lib/rdoc.rb	(revision 32304)
+++ lib/rdoc.rb	(revision 32305)
@@ -104,7 +104,7 @@
   ##
   # RDoc version you are using
 
-  VERSION = '3.7'
+  VERSION = '3.8'
 
   ##
   # Method visibilities
Index: lib/rdoc/top_level.rb
===================================================================
--- lib/rdoc/top_level.rb	(revision 32304)
+++ lib/rdoc/top_level.rb	(revision 32305)
@@ -322,6 +322,7 @@
   # Adds +an_alias+ to +Object+ instead of +self+.
 
   def add_alias(an_alias)
+    object_class.record_location self
     return an_alias unless @document_self
     object_class.add_alias an_alias
   end
@@ -330,6 +331,7 @@
   # Adds +constant+ to +Object+ instead of +self+.
 
   def add_constant(constant)
+    object_class.record_location self
     return constant unless @document_self
     object_class.add_constant constant
   end
@@ -338,6 +340,7 @@
   # Adds +include+ to +Object+ instead of +self+.
 
   def add_include(include)
+    object_class.record_location self
     return include unless @document_self
     object_class.add_include include
   end
@@ -346,6 +349,7 @@
   # Adds +method+ to +Object+ instead of +self+.
 
   def add_method(method)
+    object_class.record_location self
     return method unless @document_self
     object_class.add_method method
   end
Index: lib/rdoc/ri/store.rb
===================================================================
--- lib/rdoc/ri/store.rb	(revision 32304)
+++ lib/rdoc/ri/store.rb	(revision 32305)
@@ -268,12 +268,8 @@
     path = class_file full_name
 
     begin
-      disk_klass = nil
+      disk_klass = load_class full_name
 
-      open path, 'rb' do |io|
-        disk_klass = Marshal.load io.read
-      end
-
       klass = disk_klass.merge klass
     rescue Errno::ENOENT
     end
Index: lib/rdoc/class_module.rb
===================================================================
--- lib/rdoc/class_module.rb	(revision 32304)
+++ lib/rdoc/class_module.rb	(revision 32305)
@@ -115,7 +115,7 @@
   # across multiple runs.
 
   def add_comment comment, location
-    return if comment.empty?
+    return if comment.empty? or not document_self
 
     original = comment
 
@@ -328,7 +328,10 @@
       @comment = @comment_location = document
     end
 
-    merge_collections attributes, class_module.attributes do |add, attr|
+    cm = class_module
+    other_files = cm.in_files
+
+    merge_collections attributes, cm.attributes, other_files do |add, attr|
       if add then
         add_attribute attr
       else
@@ -337,7 +340,7 @@
       end
     end
 
-    merge_collections constants, class_module.constants do |add, const|
+    merge_collections constants, cm.constants, other_files do |add, const|
       if add then
         add_constant const
       else
@@ -346,7 +349,7 @@
       end
     end
 
-    merge_collections includes, class_module.includes do |add, incl|
+    merge_collections includes, cm.includes, other_files do |add, incl|
       if add then
         add_include incl
       else
@@ -354,7 +357,7 @@
       end
     end
 
-    merge_collections method_list, class_module.method_list do |add, meth|
+    merge_collections method_list, cm.method_list, other_files do |add, meth|
       if add then
         add_method meth
       else
@@ -367,15 +370,37 @@
   end
 
   ##
-  # Merges collection +mine+ with +other+ preferring other.
+  # Merges collection +mine+ with +other+ preferring other.  +other_files+ is
+  # used to help determine which items should be deleted.
+  #
+  # Yields whether the item should be added or removed (true or false) and the
+  # item to be added or removed.
+  #
+  #   merge_collections things, other.things, other.in_files do |add, thing|
+  #     if add then
+  #       # add the thing
+  #     else
+  #       # remove the thing
+  #     end
+  #   end
 
-  def merge_collections mine, other, &block # :nodoc:
+  def merge_collections mine, other, other_files, &block # :nodoc:
     my_things    = mine. group_by { |thing| thing.file }
     other_things = other.group_by { |thing| thing.file }
 
+    my_things.delete_if do |file, things|
+      next false unless other_files.include? file
+
+      things.each do |thing|
+        yield false, thing
+      end
+
+      true
+    end
+
     other_things.each do |file, things|
       my_things[file].each { |thing| yield false, thing } if
-        my_things.include? file
+        my_things.include?(file)
 
       things.each do |thing|
         yield true, thing
Index: lib/rdoc/parser/ruby.rb
===================================================================
--- lib/rdoc/parser/ruby.rb	(revision 32304)
+++ lib/rdoc/parser/ruby.rb	(revision 32305)
@@ -478,7 +478,7 @@
 
       read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
 
-      context.add_attribute att if att.document_self
+      context.add_attribute att
 
       @stats.add_attribute att
     else
@@ -499,6 +499,8 @@
 
     tmp = RDoc::CodeObject.new
     read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS
+    # TODO In most other places we let the context keep track of document_self
+    # and add found items appropriately but here we do not.  I'm not sure why.
     return unless tmp.document_self
 
     case tk.name
@@ -557,7 +559,7 @@
     al.line   = line_no
 
     read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
-    context.add_alias al if al.document_self
+    context.add_alias al
     @stats.add_alias al
 
     al
@@ -633,7 +635,7 @@
       cls.offset = offset
       cls.line   = line_no
 
-      cls.add_comment comment, @top_level if cls.document_self
+      cls.add_comment comment, @top_level
 
       @top_level.add_to_classes_or_modules cls
       @stats.add_class cls
@@ -657,7 +659,7 @@
 
         # notify :nodoc: all if not a constant-named class/module
         # (and remove any comment)
-        unless name =~ /\A(::)?[A-Z]/
+        unless name =~ /\A(::)?[A-Z]/ then
           other.document_self = nil
           other.document_children = false
           other.clear_comment
@@ -758,7 +760,7 @@
     read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
 
     @stats.add_constant con
-    container.add_constant con if con.document_self
+    container.add_constant con
     true
   end
 
@@ -797,7 +799,7 @@
 
       return unless meth.name
 
-      container.add_method meth if meth.document_self
+      container.add_method meth
 
       meth.comment = comment
 
@@ -818,7 +820,6 @@
       att.line      = line_no
 
       container.add_attribute att
-
       @stats.add_attribute att
     end
 
@@ -882,7 +883,6 @@
 
     tmp = RDoc::CodeObject.new
     read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS
-    return unless tmp.document_self
 
     if comment.sub!(/^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
       rw = case $1
@@ -969,7 +969,7 @@
 
       extract_call_seq comment, meth
 
-      container.add_method meth if meth.document_self
+      container.add_method meth
 
       last_tk = tk
 
@@ -1238,7 +1238,7 @@
     mod.record_location @top_level
 
     read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS
-    mod.add_comment comment, @top_level if mod.document_self
+    mod.add_comment comment, @top_level
     parse_statements(mod)
 
     @top_level.add_to_classes_or_modules mod
@@ -1341,23 +1341,15 @@
         end
 
       when TkDEF then
-        if container.document_self then
-          parse_method container, single, tk, comment
-        else
-          nest += 1
-        end
+        parse_method container, single, tk, comment
 
       when TkCONSTANT then
-        if container.document_self then
-          if not parse_constant container, tk, comment then
-            try_parse_comment = true
-          end
+        unless parse_constant container, tk, comment then
+          try_parse_comment = true
         end
 
       when TkALIAS then
-        if container.document_self and not current_method then
-          parse_alias container, single, tk, comment
-        end
+        parse_alias container, single, tk, comment unless current_method
 
       when TkYIELD then
         if current_method.nil? then
@@ -1395,12 +1387,11 @@
           when /^attr_(reader|writer|accessor)$/ then
             parse_attr_accessor container, single, tk, comment
           when 'alias_method' then
-            parse_alias container, single, tk, comment if
-              container.document_self
+            parse_alias container, single, tk, comment
           when 'require', 'include' then
             # ignore
           else
-            if container.document_self and comment =~ /\A#\#$/ then
+            if comment =~ /\A#\#$/ then
               case comment
               when /^# +:?attr(_reader|_writer|_accessor)?:/ then
                 parse_meta_attr container, single, tk, comment
@@ -1523,11 +1514,12 @@
   end
 
   ##
-  # Parses statements at the toplevel in +container+
+  # Parses statements in the top-level +container+
 
   def parse_top_level_statements(container)
     comment = collect_first_comment
     look_for_directives_in(container, comment)
+    # HACK move if to RDoc::Context#comment=
     container.comment = comment if container.document_self unless comment.empty?
     parse_statements container, NORMAL, nil, comment
   end
Index: lib/rdoc/parser/c.rb
===================================================================
--- lib/rdoc/parser/c.rb	(revision 32304)
+++ lib/rdoc/parser/c.rb	(revision 32305)
@@ -340,8 +340,6 @@
       # Ignore top-object and weird struct.c dynamic stuff
       next if var_name == "ruby_top_self"
       next if var_name == "nstr"
-      next if var_name == "envtbl"
-      next if var_name == "argf"   # it'd be nice to handle this one
 
       var_name = "rb_cObject" if var_name == "rb_mKernel"
       handle_method(type, var_name, meth_name, function, param_count,
Index: lib/rdoc/known_classes.rb
===================================================================
--- lib/rdoc/known_classes.rb	(revision 32304)
+++ lib/rdoc/known_classes.rb	(revision 32305)
@@ -26,6 +26,7 @@
     "rb_cRange"            => "Range",
     "rb_cRegexp"           => "Regexp",
     "rb_cRubyVM"           => "RubyVM",
+    "rb_cSocket"           => "Socket",
     "rb_cString"           => "String",
     "rb_cStruct"           => "Struct",
     "rb_cSymbol"           => "Symbol",
@@ -58,6 +59,7 @@
     "rb_eZeroDivError"     => "ZeroDivError",
 
     "rb_mComparable"       => "Comparable",
+    "rb_mDL"               => "DL",
     "rb_mEnumerable"       => "Enumerable",
     "rb_mErrno"            => "Errno",
     "rb_mFileTest"         => "FileTest",
Index: NEWS
===================================================================
--- NEWS	(revision 32304)
+++ NEWS	(revision 32305)
@@ -218,7 +218,7 @@
     https://github.com/jimweirich/rake/blob/master/CHANGES
 
 * RDoc
-  * RDoc has been upgraded from 2.5.8 to 3.7.  For full release notes see
+  * RDoc has been upgraded from 2.5.8 to 3.8.  For full release notes see
     http://docs.seattlerb.org/rdoc/History_txt.html
 
 * rexml
Index: test/rdoc/test_rdoc_top_level.rb
===================================================================
--- test/rdoc/test_rdoc_top_level.rb	(revision 32304)
+++ test/rdoc/test_rdoc_top_level.rb	(revision 32305)
@@ -98,6 +98,87 @@
     assert_empty RDoc::TopLevel.files
   end
 
+  def test_add_alias
+    a = RDoc::Alias.new nil, 'old', 'new', nil
+    @top_level.add_alias a
+
+    object = RDoc::TopLevel.find_class_named 'Object'
+    expected = { '#old' => [a] }
+    assert_equal expected, object.unmatched_alias_lists
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_alias_nodoc
+    @top_level.document_self = false
+
+    a = RDoc::Alias.new nil, 'old', 'new', nil
+    @top_level.add_alias a
+
+    object = RDoc::TopLevel.find_class_named('Object')
+    assert_empty object.unmatched_alias_lists
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_constant
+    const = RDoc::Constant.new 'C', nil, nil
+    @top_level.add_constant const
+
+    object = RDoc::TopLevel.find_class_named 'Object'
+    assert_equal [const], object.constants
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_constant_nodoc
+    @top_level.document_self = false
+
+    const = RDoc::Constant.new 'C', nil, nil
+    @top_level.add_constant const
+
+    object = RDoc::TopLevel.find_class_named 'Object'
+    assert_empty object.constants
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_include
+    include = RDoc::Include.new 'C', nil
+    @top_level.add_include include
+
+    object = RDoc::TopLevel.find_class_named 'Object'
+    assert_equal [include], object.includes
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_include_nodoc
+    @top_level.document_self = false
+
+    include = RDoc::Include.new 'C', nil
+    @top_level.add_include include
+
+    object = RDoc::TopLevel.find_class_named('Object')
+    assert_empty object.includes
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_method
+    method = RDoc::AnyMethod.new nil, 'm'
+    @top_level.add_method method
+
+    object = RDoc::TopLevel.find_class_named 'Object'
+    assert_equal [method], object.method_list
+    assert_includes object.in_files, @top_level
+  end
+
+  def test_add_method_stopdoc
+    @top_level.document_self = false
+
+    method = RDoc::AnyMethod.new nil, 'm'
+    @top_level.add_method method
+
+    object = RDoc::TopLevel.find_class_named('Object')
+    assert_empty object.method_list
+    assert_includes object.in_files, @top_level
+  end
+
   def test_base_name
     assert_equal 'top_level.rb', @top_level.base_name
   end
Index: test/rdoc/test_rdoc_class_module.rb
===================================================================
--- test/rdoc/test_rdoc_class_module.rb	(revision 32304)
+++ test/rdoc/test_rdoc_class_module.rb	(revision 32305)
@@ -40,6 +40,17 @@
     assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
   end
 
+  def test_add_comment_stopdoc
+    tl = RDoc::TopLevel.new 'file.rb'
+
+    cm = RDoc::ClassModule.new 'Klass'
+    cm.stop_doc
+
+    cm.add_comment '# comment 1', tl
+
+    assert_empty cm.comment
+  end
+
   def test_ancestors
     assert_equal [@parent], @child.ancestors
   end
@@ -258,6 +269,33 @@
     assert_equal expected, cm1.attributes.sort
   end
 
+  def test_merge_collections_drop
+    tl = RDoc::TopLevel.new 'file'
+
+    cm1 = RDoc::ClassModule.new 'C'
+    cm1.record_location tl
+
+    const = cm1.add_constant RDoc::Constant.new('CONST', nil, nil)
+    const.record_location tl
+
+    cm2 = RDoc::ClassModule.new 'C'
+    cm2.record_location tl
+
+    added = []
+    removed = []
+
+    cm1.merge_collections cm1.constants, cm2.constants, cm2.in_files do |add, c|
+      if add then
+        added << c
+      else
+        removed << c
+      end
+    end
+
+    assert_empty added
+    assert_equal [const], removed
+  end
+
   def test_merge_comment
     tl1 = RDoc::TopLevel.new 'one.rb'
     tl2 = RDoc::TopLevel.new 'two.rb'
Index: test/rdoc/test_rdoc_ri_store.rb
===================================================================
--- test/rdoc/test_rdoc_ri_store.rb	(revision 32304)
+++ test/rdoc/test_rdoc_ri_store.rb	(revision 32305)
@@ -1,5 +1,6 @@
 require 'rubygems'
 require 'minitest/autorun'
+require 'rdoc/rdoc'
 require 'rdoc/ri'
 require 'rdoc/markup'
 require 'tmpdir'
@@ -392,6 +393,32 @@
     assert_equal document, s.load_class('Object').comment
   end
 
+  # This is a functional test
+  def test_save_class_merge_constant
+    tl = RDoc::TopLevel.new 'file.rb'
+    klass = RDoc::NormalClass.new 'C'
+    klass.add_comment 'comment', tl
+
+    const = klass.add_constant RDoc::Constant.new('CONST', nil, nil)
+    const.record_location tl
+
+    @s.save_class klass
+
+    RDoc::RDoc.reset
+
+    klass2 = RDoc::NormalClass.new 'C'
+    klass2.record_location tl
+
+    s = RDoc::RI::Store.new @tmpdir
+    s.save_class klass2
+
+    s = RDoc::RI::Store.new @tmpdir
+
+    result = s.load_class 'C'
+
+    assert_empty result.constants
+  end
+
   def test_save_class_methods
     @s.save_class @klass
 
Index: test/rdoc/test_rdoc_parser_ruby.rb
===================================================================
--- test/rdoc/test_rdoc_parser_ruby.rb	(revision 32304)
+++ test/rdoc/test_rdoc_parser_ruby.rb	(revision 32305)
@@ -437,6 +437,21 @@
     assert                   alas.singleton
   end
 
+  def test_parse_alias_stopdoc
+    klass = RDoc::NormalClass.new 'Foo'
+    klass.parent = @top_level
+    klass.stop_doc
+
+    util_parser "alias :next= :bar"
+
+    tk = @parser.get_tk
+
+    @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
+
+    assert_empty klass.aliases
+    assert_empty klass.unmatched_alias_lists
+  end
+
   def test_parse_alias_meta
     klass = RDoc::NormalClass.new 'Foo'
     klass.parent = @top_level
@@ -472,6 +487,22 @@
     assert_equal 1, foo.line
   end
 
+  def test_parse_attr_stopdoc
+    klass = RDoc::NormalClass.new 'Foo'
+    klass.parent = @top_level
+    klass.stop_doc
+
+    comment = "##\n# my attr\n"
+
+    util_parser "attr :foo, :bar"
+
+    tk = @parser.get_tk
+
+    @parser.parse_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+    assert_empty klass.attributes
+  end
+
   def test_parse_attr_accessor
     klass = RDoc::NormalClass.new 'Foo'
     klass.parent = @top_level
@@ -515,6 +546,22 @@
     assert_equal 0, klass.attributes.length
   end
 
+  def test_parse_attr_accessor_stopdoc
+    klass = RDoc::NormalClass.new 'Foo'
+    klass.parent = @top_level
+    klass.stop_doc
+
+    comment = "##\n# my attr\n"
+
+    util_parser "attr_accessor :foo, :bar"
+
+    tk = @parser.get_tk
+
+    @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+    assert_empty klass.attributes
+  end
+
   def test_parse_attr_accessor_writer
     klass = RDoc::NormalClass.new 'Foo'
     klass.parent = @top_level
@@ -620,6 +667,22 @@
     assert_equal @top_level, foo.file
   end
 
+  def test_parse_meta_attr_stopdoc
+    klass = RDoc::NormalClass.new 'Foo'
+    klass.parent = @top_level
+    klass.stop_doc
+
+    comment = "##\n# :attr: \n# my method\n"
+
+    util_parser "add_my_method :foo, :bar"
+
+    tk = @parser.get_tk
+
+    @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+    assert_empty klass.attributes
+  end
+
   def test_parse_meta_attr_writer
     klass = RDoc::NormalClass.new 'Foo'
     klass.parent = @top_level
@@ -640,7 +703,7 @@
   end
 
   def test_parse_class
-    comment = "##\n# my method\n"
+    comment = "##\n# my class\n"
 
     util_parser "class Foo\nend"
 
@@ -650,7 +713,7 @@
 
     foo = @top_level.classes.first
     assert_equal 'Foo', foo.full_name
-    assert_equal 'my method', foo.comment
+    assert_equal 'my class', foo.comment
     assert_equal [@top_level], foo.in_files
     assert_equal 0, foo.offset
     assert_equal 1, foo.line
@@ -706,6 +769,42 @@
     assert_equal 2, foo.method_list.length
   end
 
+  def test_parse_class_nodoc
+    comment = "##\n# my class\n"
+
+    util_parser "class Foo # :nodoc:\nend"
+
+    tk = @parser.get_tk
+
+    @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+    foo = @top_level.classes.first
+    assert_equal 'Foo', foo.full_name
+    assert_empty foo.comment
+    assert_equal [@top_level], foo.in_files
+    assert_equal 0, foo.of (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]