Skip to content

Commit d659484

Browse files
authored
Remove dead or unnecessary methods/attributes (#1315)
2 types of targets in this PR: - Completely unused methods (outside of tests, ofc) - Single-used or unnecessary methods. Like: ```rb def each_constant # :yields: constant @constants.each {|c| yield c} end ```
1 parent 56a28a1 commit d659484

18 files changed

+12
-170
lines changed

lib/rdoc/code_object.rb

-28
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ class RDoc::CodeObject
9090

9191
attr_reader :store
9292

93-
##
94-
# We are the model of the code, but we know that at some point we will be
95-
# worked on by viewers. By implementing the Viewable protocol, viewers can
96-
# associated themselves with these objects.
97-
98-
attr_accessor :viewer
99-
10093
##
10194
# When mixed-in to a class, this points to the Context in which it was originally defined.
10295

@@ -217,20 +210,6 @@ def done_documenting=(value)
217210
@document_children = @document_self
218211
end
219212

220-
##
221-
# Yields each parent of this CodeObject. See also
222-
# RDoc::ClassModule#each_ancestor
223-
224-
def each_parent
225-
code_object = self
226-
227-
while code_object = code_object.parent do
228-
yield code_object
229-
end
230-
231-
self
232-
end
233-
234213
##
235214
# File name where this CodeObject was found.
236215
#
@@ -327,13 +306,6 @@ def parent
327306
end
328307
end
329308

330-
##
331-
# File name of our parent
332-
333-
def parent_file_name
334-
@parent ? @parent.base_name : '(unknown)'
335-
end
336-
337309
##
338310
# Name of our parent
339311

lib/rdoc/code_object/alias.rb

-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ def aref
5959
"#alias-#{type}-#{html_name}"
6060
end
6161

62-
##
63-
# Full old name including namespace
64-
65-
def full_old_name
66-
@full_name || "#{parent.name}#{pretty_old_name}"
67-
end
68-
6962
##
7063
# HTML id-friendly version of +#new_name+.
7164

lib/rdoc/code_object/class_module.rb

-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class RDoc::ClassModule < RDoc::Context
3434

3535
attr_accessor :comment_location
3636

37-
attr_accessor :diagram # :nodoc:
38-
3937
##
4038
# Class or module this constant is an alias for
4139

@@ -56,7 +54,6 @@ def self.from_module class_type, mod
5654

5755
klass.parent = mod.parent
5856
klass.section = mod.section
59-
klass.viewer = mod.viewer
6057

6158
klass.attributes.concat mod.attributes
6259
klass.method_list.concat mod.method_list
@@ -110,7 +107,6 @@ def self.from_module class_type, mod
110107

111108
def initialize(name, superclass = nil)
112109
@constant_aliases = []
113-
@diagram = nil
114110
@is_alias_for = nil
115111
@name = name
116112
@superclass = superclass

lib/rdoc/code_object/context.rb

+1-43
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,6 @@ def current_section
688688
section
689689
end
690690

691-
##
692-
# Is part of this thing was defined in +file+?
693-
694-
def defined_in?(file)
695-
@in_files.include?(file)
696-
end
697-
698691
def display(method_attr) # :nodoc:
699692
if method_attr.is_a? RDoc::Attr
700693
"#{method_attr.definition} #{method_attr.pretty_name}"
@@ -713,41 +706,13 @@ def display(method_attr) # :nodoc:
713706
def each_ancestor(&_) # :nodoc:
714707
end
715708

716-
##
717-
# Iterator for attributes
718-
719-
def each_attribute # :yields: attribute
720-
@attributes.each { |a| yield a }
721-
end
722-
723709
##
724710
# Iterator for classes and modules
725711

726712
def each_classmodule(&block) # :yields: module
727713
classes_and_modules.sort.each(&block)
728714
end
729715

730-
##
731-
# Iterator for constants
732-
733-
def each_constant # :yields: constant
734-
@constants.each {|c| yield c}
735-
end
736-
737-
##
738-
# Iterator for included modules
739-
740-
def each_include # :yields: include
741-
@includes.each do |i| yield i end
742-
end
743-
744-
##
745-
# Iterator for extension modules
746-
747-
def each_extend # :yields: extend
748-
@extends.each do |e| yield e end
749-
end
750-
751716
##
752717
# Iterator for methods
753718

@@ -847,13 +812,6 @@ def find_external_alias_named(name)
847812
end
848813
end
849814

850-
##
851-
# Finds a file with +name+ in this context
852-
853-
def find_file_named name
854-
@store.find_file_named name
855-
end
856-
857815
##
858816
# Finds an instance method with +name+ in this context
859817

@@ -871,7 +829,7 @@ def find_local_symbol(symbol)
871829
find_attribute_named(symbol) or
872830
find_external_alias_named(symbol) or
873831
find_module_named(symbol) or
874-
find_file_named(symbol)
832+
@store.find_file_named(symbol)
875833
end
876834

877835
##

lib/rdoc/code_object/method_attr.rb

-13
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,6 @@ def name_prefix
313313
@singleton ? '::' : '#'
314314
end
315315

316-
##
317-
# Name for output to HTML. For class methods the full name with a "." is
318-
# used like +SomeClass.method_name+. For instance methods the class name is
319-
# used if +context+ does not match the parent.
320-
#
321-
# This is to help prevent people from using :: to call class methods.
322-
323-
def output_name context
324-
return "#{name_prefix}#{@name}" if context == parent
325-
326-
"#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
327-
end
328-
329316
##
330317
# Method/attribute name with class/instance indicator
331318

lib/rdoc/code_object/require.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def inspect # :nodoc:
2424
self.class,
2525
object_id,
2626
@name,
27-
parent_file_name,
27+
@parent ? @parent.base_name : '(unknown)'
2828
]
2929
end
3030

lib/rdoc/code_object/top_level.rb

-18
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context
66

77
MARSHAL_VERSION = 0 # :nodoc:
88

9-
##
10-
# This TopLevel's File::Stat struct
11-
12-
attr_accessor :file_stat
13-
149
##
1510
# Relative name of this file
1611

@@ -28,8 +23,6 @@ class RDoc::TopLevel < RDoc::Context
2823

2924
attr_reader :classes_or_modules
3025

31-
attr_accessor :diagram # :nodoc:
32-
3326
##
3427
# The parser class that processed this file
3528

@@ -45,8 +38,6 @@ def initialize absolute_name, relative_name = absolute_name
4538
@name = nil
4639
@absolute_name = absolute_name
4740
@relative_name = relative_name
48-
@file_stat = File.stat(absolute_name) rescue nil # HACK for testing
49-
@diagram = nil
5041
@parser = nil
5142

5243
@classes_or_modules = []
@@ -186,13 +177,6 @@ def inspect # :nodoc:
186177
]
187178
end
188179

189-
##
190-
# Time this file was last modified, if known
191-
192-
def last_modified
193-
@file_stat ? file_stat.mtime : nil
194-
end
195-
196180
##
197181
# Dumps this TopLevel for use by ri. See also #marshal_load
198182

@@ -213,8 +197,6 @@ def marshal_load array # :nodoc:
213197

214198
@parser = array[2]
215199
@comment = RDoc::Comment.from_document array[3]
216-
217-
@file_stat = nil
218200
end
219201

220202
##

lib/rdoc/generator/pot/message_extractor.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def extract_from_klass klass
3535
end
3636
end
3737

38-
klass.each_constant do |constant|
38+
klass.constants.each do |constant|
3939
extract_text(constant.comment, constant.full_name)
4040
end
4141

42-
klass.each_attribute do |attribute|
42+
klass.attributes.each do |attribute|
4343
extract_text(attribute.comment, attribute.full_name)
4444
end
4545

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h3>Extended With Modules</h3>
44

55
<ul class="link-list">
6-
<%- klass.each_extend do |ext| -%>
6+
<%- klass.extends.each do |ext| -%>
77
<%- unless String === ext.module then -%>
88
<li><a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a>
99
<%- else -%>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h3>Included Modules</h3>
44

55
<ul class="link-list">
6-
<%- klass.each_include do |inc| -%>
6+
<%- klass.includes.each do |inc| -%>
77
<%- unless String === inc.module then -%>
88
<li><a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a>
99
<%- else -%>

lib/rdoc/stats.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def report_attributes cm
261261

262262
report = []
263263

264-
cm.each_attribute do |attr|
264+
cm.attributes.each do |attr|
265265
next if attr.documented?
266266
line = attr.line ? ":#{attr.line}" : nil
267267
report << " #{attr.definition} :#{attr.name} # in file #{attr.file.full_name}#{line}\n"
@@ -331,7 +331,7 @@ def report_constants cm
331331

332332
report = []
333333

334-
cm.each_constant do |constant|
334+
cm.constants.each do |constant|
335335
# TODO constant aliases are listed in the summary but not reported
336336
# figure out what to do here
337337
next if constant.documented? || constant.is_alias_for

lib/rdoc/store.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ def save
762762
save_method klass, method
763763
end
764764

765-
klass.each_attribute do |attribute|
765+
klass.attributes.each do |attribute|
766766
save_method klass, attribute
767767
end
768768
end

test/rdoc/test_rdoc_class_module.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ def test_update_extends
14741474
@c1.add_extend a
14751475
@c1.add_extend b
14761476
@c1.add_extend c
1477-
@c1.each_extend do |extend| extend.module end # cache extended modules
1477+
@c1.extends.each do |extend| extend.module end # cache extended modules
14781478

14791479
@m1_m2.document_self = nil
14801480
assert @m1_m2.remove_from_documentation?
@@ -1495,7 +1495,7 @@ def test_update_extends_trim
14951495

14961496
@c1.add_extend a
14971497
@c1.add_extend b
1498-
@c1.each_extend do |extend| extend.module end # cache extended modules
1498+
@c1.extends.each do |extend| extend.module end # cache extended modules
14991499

15001500
@c1.update_extends
15011501

@@ -1510,7 +1510,7 @@ def test_update_extends_with_colons
15101510
@c1.add_extend a
15111511
@c1.add_extend b
15121512
@c1.add_extend c
1513-
@c1.each_extend do |extend| extend.module end # cache extended modules
1513+
@c1.extends.each do |extend| extend.module end # cache extended modules
15141514

15151515
@m1_m2.document_self = nil
15161516
assert @m1_m2.remove_from_documentation?

test/rdoc/test_rdoc_code_object.rb

-15
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,6 @@ def test_done_documenting
201201
refute @co.done_documenting
202202
end
203203

204-
def test_each_parent
205-
parents = []
206-
207-
@parent_m.each_parent do |code_object|
208-
parents << code_object
209-
end
210-
211-
assert_equal [@parent, @xref_data], parents
212-
end
213-
214204
def test_file_name
215205
assert_nil @co.file_name
216206

@@ -275,11 +265,6 @@ def test_metadata
275265
assert_equal 'not_rdoc', @co.metadata['markup']
276266
end
277267

278-
def test_parent_file_name
279-
assert_equal '(unknown)', @co.parent_file_name
280-
assert_equal 'xref_data.rb', @c1.parent_file_name
281-
end
282-
283268
def test_parent_name
284269
assert_equal '(unknown)', @co.parent_name
285270
assert_equal 'xref_data.rb', @c1.parent_name

test/rdoc/test_rdoc_context.rb

-11
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,6 @@ def test_current_section
437437
assert_equal default_section, @context.current_section
438438
end
439439

440-
def test_defined_in_eh
441-
assert @c1.defined_in?(@c1.top_level)
442-
443-
refute @c1.defined_in?(@store.add_file('name.rb'))
444-
end
445-
446440
def test_equals2
447441
assert_equal @c3, @c3
448442
refute_equal @c2, @c3
@@ -538,11 +532,6 @@ def test_find_enclosing_module_named
538532
assert_equal @c2, @c2_c3.find_enclosing_module_named('C2')
539533
end
540534

541-
def test_find_file_named
542-
assert_nil @c1.find_file_named('nonexistent.rb')
543-
assert_equal @xref_data, @c1.find_file_named(@file_name)
544-
end
545-
546535
def test_find_instance_method_named
547536
assert_nil @c1.find_instance_method_named('none')
548537

0 commit comments

Comments
 (0)