Skip to content

Commit d4da155

Browse files
committed
Remove dead Section#extract_comment method
Earlopain split section-comment extraction out of Section#extract_comment in #1639 and added the TODO "Remove when the ripper parser has been removed". With ripper gone, the Ruby parser's own extract_section_comment is the only path that fires; every production caller hands Section.add_comment a comment that has already been stripped of the ":section:" header. - Drop Section#extract_comment, and simplify Section#add_comment to just validate and append. - Update test_add_comment / test_description to pass the empty, pre-extracted comments the parser actually produces today. - Drop test_extract_comment. Also restore the explanatory note above Mixin#module that the prior commit removed too aggressively. The method's resolution dance is still live for the C parser (which passes unresolved local names); only the Ruby parser's mixins arrive pre-resolved.
1 parent 9570cdc commit d4da155

3 files changed

Lines changed: 13 additions & 49 deletions

File tree

lib/rdoc/code_object/context/section.rb

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def ==(other)
6363
# Adds +comment+ to this section
6464

6565
def add_comment(comment)
66-
comments = Array(comment)
67-
comments.each do |c|
68-
extracted_comment = extract_comment(c)
69-
@comments << extracted_comment unless extracted_comment.empty?
66+
Array(comment).each do |c|
67+
next if c.nil?
68+
raise TypeError, "unknown comment #{c.inspect}" unless RDoc::Comment === c
69+
@comments << c unless c.empty?
7070
end
7171
end
7272

@@ -98,37 +98,6 @@ def legacy_aref
9898
CGI.escape(title).gsub('%', '-').sub(/^-/, '')
9999
end
100100

101-
##
102-
# Extracts the comment for this section from the original comment block.
103-
# If the first line contains :section:, strip it and use the rest.
104-
# Otherwise remove lines up to the line containing :section:, and look
105-
# for those lines again at the end and remove them. This lets us write
106-
#
107-
# # :section: The title
108-
# # The body
109-
110-
def extract_comment(comment)
111-
case comment
112-
when nil
113-
RDoc::Comment.new ''
114-
when RDoc::Comment then
115-
if comment.text =~ /^#[ \t]*:section:.*\n/ then
116-
start = $`
117-
rest = $'
118-
119-
comment.text = if start.empty? then
120-
rest
121-
else
122-
rest.sub(/#{start.chomp}\Z/, '')
123-
end
124-
end
125-
126-
comment
127-
else
128-
raise TypeError, "unknown comment #{comment.inspect}"
129-
end
130-
end
131-
132101
def inspect # :nodoc:
133102
"#<%s:0x%x %p>" % [self.class, object_id, title]
134103
end

lib/rdoc/code_object/mixin.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def inspect # :nodoc:
7171
# lookup behavior.
7272
#
7373
# As of the beginning of October, 2011, no gem includes nonexistent modules.
74+
#
75+
# The Ruby parser passes an already-resolved full-path +name+, so most of this
76+
# logic only runs for the C parser, which passes the unresolved local name.
7477

7578
def module
7679
return @module if @module

test/rdoc/rdoc_context_section_test.rb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def test_add_comment
1919

2020
klass = file1.add_class RDoc::NormalClass, 'Klass'
2121

22-
c1 = RDoc::Comment.new "# :section: section\n", file1
23-
c2 = RDoc::Comment.new "# hello\n", file1
24-
c3 = RDoc::Comment.new "# world\n", file1
22+
c1 = RDoc::Comment.new "", file1
23+
c2 = RDoc::Comment.new "# hello\n", file1
24+
c3 = RDoc::Comment.new "# world\n", file1
2525

2626
s = @S.new klass, 'section', c1
2727

@@ -45,9 +45,9 @@ def test_description
4545
klass = file1.add_class RDoc::NormalClass, 'Klass'
4646

4747

48-
c1 = comment "# :section: section\n", file1, :ruby
49-
c2 = comment "# hello\n", file1, :ruby
50-
c3 = comment "# <tt>world</tt>\n", file1, :ruby
48+
c1 = comment '', file1, :ruby
49+
c2 = comment "# hello\n", file1, :ruby
50+
c3 = comment "# <tt>world</tt>\n", file1, :ruby
5151

5252
s = @S.new klass, 'section', c1, @store
5353
assert_equal '', s.description
@@ -83,14 +83,6 @@ def test_equals
8383
refute_equal @s, other
8484
end
8585

86-
def test_extract_comment
87-
assert_equal '', @s.extract_comment(comment('')).text
88-
assert_equal '', @s.extract_comment(comment("# :section: b\n")).text
89-
assert_equal '# c', @s.extract_comment(comment("# :section: b\n# c")).text
90-
assert_equal '# c',
91-
@s.extract_comment(comment("# a\n# :section: b\n# c")).text
92-
end
93-
9486
def test_hash
9587
other = @S.new @klass, 'other', comment('# comment', @top_level)
9688

0 commit comments

Comments
 (0)