Skip to content

Commit 1233c61

Browse files
committed
Merge pull request ruby#115 from erikh/superclass_report
Methods that use super are now shown in rdoc HTML view
2 parents 32130be + a4fc755 commit 1233c61

File tree

8 files changed

+107
-1
lines changed

8 files changed

+107
-1
lines changed

lib/rdoc/any_method.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class RDoc::AnyMethod < RDoc::MethodAttr
2525

2626
attr_accessor :params
2727

28+
##
29+
# Uses superclass implementation
30+
31+
attr_accessor :uses_superclass
32+
2833
include RDoc::TokenStream
2934

3035
##
@@ -36,6 +41,27 @@ def initialize text, name
3641
@c_function = nil
3742
@dont_rename_initialize = false
3843
@token_stream = nil
44+
@uses_superclass = false
45+
end
46+
47+
##
48+
# For methods that use the superclass, find the next superclass method that
49+
# would be called.
50+
51+
def find_superclass_method
52+
return nil unless uses_superclass
53+
54+
method = nil
55+
next_superclass = parent.superclass
56+
57+
until next_superclass.kind_of?(String) or !next_superclass
58+
if method = next_superclass.method_list.find { |x| x == self }
59+
break
60+
end
61+
next_superclass = next_superclass.superclass
62+
end
63+
64+
return method
3965
end
4066

4167
##

lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<ul class="link-list">
77
<% klass.each_method do |meth| %>
8-
<li><a href="#<%= meth.aref %>"><%= meth.singleton ? '::' : '#' %><%= h meth.name %></a>
8+
<li <% if meth.uses_superclass %> class="superclass" <% end %>><a href="#<%= meth.aref %>"><%= meth.singleton ? '::' : '#' %><%= h meth.name %></a>
99
<% end %>
1010
</ul>
1111
</nav>

lib/rdoc/generator/template/darkfish/class.rhtml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@
130130
<% else %>
131131
<p class="missing-docs">(Not documented)
132132
<% end %>
133+
<% if method.uses_superclass %>
134+
<div class="method-superclass">
135+
Calls superclass method
136+
<%=
137+
method.find_superclass_method ?
138+
method.formatter.link(method.find_superclass_method.full_name, method.find_superclass_method.full_name) :
139+
method.parent.superclass
140+
%>
141+
</div>
142+
<% end %>
133143

134144
<% if method.token_stream then %>
135145
<div class="method-source-code" id="<%= method.html_name %>-source">
372 Bytes
Loading

lib/rdoc/generator/template/darkfish/rdoc.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88

9+
/* vim: ft=css et sw=2 ts=2 sts=2 */
910
/* Base Green is: #6C8C22 */
1011

1112
* { padding: 0; margin: 0; }
@@ -212,7 +213,9 @@ dl.svninfo dt {
212213

213214
ul.link-list li {
214215
white-space: nowrap;
216+
line-height: 20px;
215217
}
218+
216219
ul.link-list .type {
217220
font-size: 8px;
218221
text-transform: uppercase;
@@ -222,6 +225,10 @@ ul.link-list .type {
222225
-webkit-border-radius: 5px;
223226
}
224227

228+
ul.link-list li.superclass {
229+
background: url(images/arrow_up.png) no-repeat right center;
230+
}
231+
225232
/* @end */
226233

227234
/* @group Class Metadata Section */
@@ -394,6 +401,11 @@ ul.link-list .type {
394401
display: none;
395402
}
396403

404+
#documentation .method-description .method-superclass {
405+
color: #333;
406+
font-weight: bolder;
407+
}
408+
397409
#documentation .method-detail {
398410
margin: 0.5em 0;
399411
padding: 0.5em 0;

lib/rdoc/parser/ruby.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,9 @@ def parse_statements(container, single = NORMAL, current_method = nil,
13881388
when TkCASE, TkDO, TkIF, TkUNLESS, TkBEGIN then
13891389
nest += 1
13901390

1391+
when TkSUPER then
1392+
current_method.uses_superclass = true
1393+
13911394
when TkIDENTIFIER then
13921395
if nest == 1 and current_method.nil? then
13931396
case tk.name

test/test_rdoc_any_method.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,34 @@ def test_parent_name
244244
assert_equal 'C1', @c1.method_list.last.parent_name
245245
end
246246

247+
def test_find_superclass_method
248+
k3 = RDoc::NormalClass.new "RDoc::CodeObject", nil
249+
k2 = RDoc::NormalClass.new "RDoc::MethodAttr", k3
250+
k = RDoc::NormalClass.new "RDoc::AnyMethod", k2
251+
252+
m = RDoc::AnyMethod.new "def test_super", "test_super"
253+
m2 = RDoc::AnyMethod.new "def test_super", "test_super"
254+
m3 = RDoc::AnyMethod.new "def test_no_super", "test_no_super"
255+
256+
m.uses_superclass = true
257+
k.add_method m
258+
k.add_method m3
259+
260+
k2.add_method m2
261+
262+
assert_nil(m3.find_superclass_method, 'no superclass method for "test_no_super"')
263+
assert_equal(m2, m.find_superclass_method, 'superclass method found for "test_super"')
264+
265+
k2 = RDoc::NormalClass.new "RDoc::MethodAttr", k3
266+
k = RDoc::NormalClass.new "RDoc::AnyMethod", k2
267+
268+
m.uses_superclass = true
269+
k.add_method m
270+
k.add_method m3
271+
272+
k3.add_method m2
273+
274+
assert_equal(m2, m.find_superclass_method, 'superclass method found two levels up')
275+
end
247276
end
248277

test/test_rdoc_parser_ruby.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,32 @@ class Baz
24562456
assert_equal 'there', baz.comment.text
24572457
end
24582458

2459+
def test_uses_superclass
2460+
util_parser <<-EOS
2461+
class Bar
2462+
def bar
2463+
end
2464+
end
2465+
class Foo < Bar
2466+
def bar
2467+
super
2468+
end
2469+
end
2470+
EOS
2471+
2472+
@parser.parse_statements @top_level
2473+
2474+
bar = @top_level.classes.first
2475+
foo = @top_level.classes.last
2476+
2477+
foo_bar = foo.method_list.first
2478+
bar_bar = bar.method_list.first
2479+
2480+
assert(foo_bar.uses_superclass)
2481+
assert_equal(bar_bar, foo_bar.find_superclass_method)
2482+
refute(bar_bar.uses_superclass)
2483+
end
2484+
24592485
def tk(klass, line, char, name, text)
24602486
klass = RDoc::RubyToken.const_get "Tk#{klass.to_s.upcase}"
24612487

0 commit comments

Comments
 (0)