Skip to content

Commit d4ff3f6

Browse files
committed
Move @full_name initialization up to RDoc::CodeObject
1 parent 3d5fc2a commit d4ff3f6

File tree

7 files changed

+54
-32
lines changed

7 files changed

+54
-32
lines changed

lib/rdoc/class_module.rb

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ def self.from_module(class_type, mod)
5959

6060
# update the parent of all children
6161

62-
(klass.attributes
63-
klass.method_list +
64-
klass.aliases +
65-
klass.external_aliases +
66-
klass.constants +
67-
klass.includes +
68-
klass.classes +
69-
klass.modules).each do |obj|
62+
(klass.attributes +
63+
klass.method_list +
64+
klass.aliases +
65+
klass.external_aliases +
66+
klass.constants +
67+
klass.includes +
68+
klass.classes +
69+
klass.modules).each do |obj|
7070
obj.parent = klass
71+
obj.full_name = nil
7172
end
7273

7374
klass
@@ -81,7 +82,6 @@ def self.from_module(class_type, mod)
8182
def initialize(name, superclass = nil)
8283
@constant_aliases = []
8384
@diagram = nil
84-
@full_name = nil
8585
@is_alias_for = nil
8686
@name = name
8787
@superclass = superclass
@@ -173,15 +173,6 @@ def full_name
173173
end
174174
end
175175

176-
##
177-
# Sets the full_name overriding any computed full name.
178-
#
179-
# Used for modules and classes that are constant aliases.
180-
181-
def full_name= full_name
182-
@full_name = full_name
183-
end
184-
185176
def marshal_dump # :nodoc:
186177
# TODO must store the singleton attribute
187178
attrs = attributes.sort.map do |attr|

lib/rdoc/code_object.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ class RDoc::CodeObject
9191
# Creates a new CodeObject that will document itself and its children
9292

9393
def initialize
94-
@metadata = {}
95-
@comment = ''
96-
@parent = nil
97-
@file = nil
94+
@metadata = {}
95+
@comment = ''
96+
@parent = nil
97+
@file = nil
98+
@full_name = nil
9899

99100
@document_children = true
100101
@document_self = true
@@ -171,6 +172,15 @@ def force_documentation=(value)
171172
@force_documentation = value unless @done_documenting
172173
end
173174

175+
##
176+
# Sets the full_name overriding any computed full name.
177+
#
178+
# Set to +nil+ to clear RDoc's cached value
179+
180+
def full_name= full_name
181+
@full_name = full_name
182+
end
183+
174184
##
175185
# File name of our parent
176186

lib/rdoc/context.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,17 @@ def add_class class_type, given_name, superclass = '::Object'
416416
# to +self+, and its #section to #current_section. Returns +mod+.
417417

418418
def add_class_or_module mod, self_hash, all_hash
419-
mod.section = @current_section # TODO declaring context? something is wrong here...
419+
mod.section = @current_section # TODO declaring context? something is
420+
# wrong here...
420421
mod.parent = self
422+
421423
unless @done_documenting then
422424
self_hash[mod.name] = mod
423-
# this must be done AFTER adding mod to its parent,
424-
# so that the full name is correct:
425+
# this must be done AFTER adding mod to its parent, so that the full
426+
# name is correct:
425427
all_hash[mod.full_name] = mod
426428
end
429+
427430
mod
428431
end
429432

@@ -484,8 +487,10 @@ def add_method(method)
484487
def add_module(class_type, name)
485488
mod = @classes[name] || @modules[name]
486489
return mod if mod
487-
full_name = child_name(name)
490+
491+
full_name = child_name name
488492
mod = RDoc::TopLevel.modules_hash[full_name] || class_type.new(name)
493+
489494
add_class_or_module(mod, @modules, RDoc::TopLevel.modules_hash)
490495
end
491496

@@ -1011,7 +1016,8 @@ def to_s # :nodoc:
10111016
##
10121017
# Return the TopLevel that owns us
10131018
#--
1014-
# FIXME we can be 'owned' by several TopLevel (see #record_location & #in_files)
1019+
# FIXME we can be 'owned' by several TopLevel (see #record_location &
1020+
# #in_files)
10151021

10161022
def top_level
10171023
return @top_level if defined? @top_level
@@ -1029,8 +1035,8 @@ def upgrade_to_class mod, class_type, enclosing
10291035
klass = RDoc::ClassModule.from_module class_type, mod
10301036

10311037
# if it was there, then we keep it even if done_documenting
1032-
RDoc::TopLevel.classes_hash[full_name] = klass
1033-
enclosing.classes_hash[name] = klass
1038+
RDoc::TopLevel.classes_hash[mod.full_name] = klass
1039+
enclosing.classes_hash[mod.name] = klass
10341040

10351041
klass
10361042
end

lib/rdoc/method_attr.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def initialize text, name
9292
@arglists = nil
9393
@block_params = nil
9494
@call_seq = nil
95-
@full_name = nil
9695
@param_seq = nil
9796
@params = nil
9897
end

lib/rdoc/ruby_lex.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,12 @@ def identify_gvar
823823
end
824824
end
825825

826+
IDENT_RE = if defined? Encoding then
827+
/[\w\u0080-\uFFFF]/u
828+
else
829+
/[\w\x80-\xFF]/
830+
end
831+
826832
def identify_identifier
827833
token = ""
828834
if peek(0) =~ /[$@]/
@@ -832,7 +838,7 @@ def identify_identifier
832838
end
833839
end
834840

835-
while (ch = getc) =~ /[\w\u0080-\uFFFF]/u do
841+
while (ch = getc) =~ IDENT_RE do
836842
print " :#{ch}: " if RDoc::RubyLex.debug?
837843
token.concat ch
838844
end

test/test_rdoc_any_method.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_markup_code
5454
]
5555

5656
@c2_a.collect_tokens
57-
@c2_a.add_tokens *tokens
57+
@c2_a.add_tokens(*tokens)
5858

5959
expected = [
6060
'<span class="ruby-constant">CONSTANT</span>',

test/test_rdoc_code_object.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ def test_done_documenting
9191
assert @co.document_children
9292
end
9393

94+
def test_full_name_equals
95+
@co.full_name = 'hi'
96+
97+
assert_equal 'hi', @co.instance_variable_get(:@full_name)
98+
99+
@co.full_name = nil
100+
101+
assert_nil @co.instance_variable_get(:@full_name)
102+
end
103+
94104
def test_metadata
95105
assert_empty @co.metadata
96106

0 commit comments

Comments
 (0)