Permalink
Browse files

Fixed duplicate comments for modules from C

To workaround a C parser bug add_comment only allows a comment to be
added once.
  • Loading branch information...
1 parent ecae6cb commit d84ada248f8f3c2fffa5f81ce60dfc9a7bc9b8c6 @drbrain drbrain committed Dec 14, 2012
Showing with 32 additions and 15 deletions.
  1. +2 −4 lib/rdoc/class_module.rb
  2. +22 −8 lib/rdoc/store.rb
  3. +2 −2 test/test_rdoc_class_module.rb
  4. +6 −1 test/test_rdoc_store.rb
View
@@ -31,7 +31,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Comment and the location it came from. Use #add_comment to add comments
- attr_reader :comment_location
+ attr_accessor :comment_location
attr_accessor :diagram # :nodoc:
@@ -135,9 +135,7 @@ def add_comment comment, location
normalize_comment comment
end
- return if @comment_location.any? do |(c, l)|
- c == comment and l == location
- end
+ @comment_location.delete_if { |(_, l)| l == location }
@comment_location << [comment, location]
View
@@ -348,9 +348,16 @@ def find_c_enclosure variable
@c_enclosure_classes.fetch variable do
break unless name = @c_enclosure_names[variable]
- mod = find_class_or_module(name) || load_class(name)
+ mod = find_class_or_module name
- break unless mod
+ unless mod then
+ loaded_mod = load_class_data name
+
+ file = loaded_mod.in_files.first
+ file.store = self
+
+ mod = file.add_module RDoc::NormalModule, name
+ end
@c_enclosure_classes[variable] = mod
end
@@ -568,14 +575,10 @@ def load_cache
end
##
- # Loads ri data for +klass_name+
+ # Loads ri data for +klass_name+ and hooks it up to this store.
def load_class klass_name
- file = class_file klass_name
-
- obj = open file, 'rb' do |io|
- Marshal.load io.read
- end
+ obj = load_class_data klass_name
obj.store = self
@@ -585,6 +588,17 @@ def load_class klass_name
when RDoc::NormalModule then
@modules_hash[klass_name] = obj
end
+ end
+
+ ##
+ # Loads ri data for +klass_name+
+
+ def load_class_data klass_name
+ file = class_file klass_name
+
+ obj = open file, 'rb' do |io|
+ Marshal.load io.read
+ end
rescue Errno::ENOENT => e
error = MissingFileError.new(self, file, klass_name)
error.set_backtrace e.backtrace
@@ -46,9 +46,9 @@ def test_add_comment_duplicate
cm = RDoc::ClassModule.new 'Klass'
cm.add_comment '# comment 1', tl1
- cm.add_comment '# comment 1', tl1
+ cm.add_comment '# comment 2', tl1
- assert_equal [['comment 1', tl1]], cm.comment_location
+ assert_equal [['comment 2', tl1]], cm.comment_location
end
def test_add_comment_stopdoc
View
@@ -18,6 +18,7 @@ def setup
@klass = @top_level.add_class RDoc::NormalClass, 'Object'
@klass.add_comment 'original', @top_level
+ @klass.record_location @top_level
@cmeth = RDoc::AnyMethod.new nil, 'cmethod'
@cmeth.singleton = true
@@ -264,7 +265,11 @@ def test_find_c_enclosure_from_cache
@s.c_enclosure_names['cObject'] = 'Object'
- assert_equal @klass, @s.find_c_enclosure('cObject')
+ klass = @s.find_c_enclosure('cObject')
+ assert_equal @klass, klass
+
+ assert_empty klass.comment_location
+ assert_equal @top_level, klass.parent
assert_includes @s.c_enclosure_classes, 'cObject'
end

0 comments on commit d84ada2

Please sign in to comment.