Skip to content

Commit

Permalink
Fixed duplicate comments for modules from C
Browse files Browse the repository at this point in the history
To workaround a C parser bug add_comment only allows a comment to be
added once.
  • Loading branch information
drbrain committed Dec 14, 2012
1 parent ecae6cb commit d84ada2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
6 changes: 2 additions & 4 deletions lib/rdoc/class_module.rb
Expand Up @@ -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:

Expand Down Expand Up @@ -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]

Expand Down
30 changes: 22 additions & 8 deletions lib/rdoc/store.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_rdoc_class_module.rb
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion test/test_rdoc_store.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d84ada2

Please sign in to comment.