Skip to content

Commit

Permalink
Record location of module alias
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Jan 10, 2011
1 parent 0c05ac7 commit 14c80df
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
5 changes: 5 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
=== 3.4.1

* Bug fixes
* Locations of module aliases are now recorded.

=== 3.4

* Minor enhancements
Expand Down
17 changes: 11 additions & 6 deletions lib/rdoc/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,13 @@ def add_constant(constant)
# HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
# (this is a #ifdef: should be handled by the C parser)
known = @constants_hash[constant.name]
if known
#$stderr.puts "\nconstant #{constant.name} already registered"

if known then
known.comment = constant.comment if known.comment.empty?
known.value = constant.value if known.value.nil? or known.value.strip.empty?

known.value = constant.value if
known.value.nil? or known.value.strip.empty?

known.is_alias_for ||= constant.is_alias_for
else
@constants_hash[constant.name] = constant
Expand Down Expand Up @@ -494,9 +497,10 @@ def add_module(class_type, name)
end

##
# Adds an alias from +from+ (a class or module) to +name+.
# Adds an alias from +from+ (a class or module) to +name+ which was defined
# in +file+.

def add_module_alias from, name
def add_module_alias from, name, file
return from if @done_documenting

to_name = child_name(name)
Expand All @@ -518,7 +522,8 @@ def add_module_alias from, name
# HACK: register a constant for this alias:
# constant value and comment will be updated after,
# when the Ruby parser adds the constant
const = RDoc::Constant.new(name, nil, '')
const = RDoc::Constant.new name, nil, ''
const.record_location file
const.is_alias_for = from
add_constant const

Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def parse_constant(container, tk, comment)
container.find_module_named rhs_name
end

container.add_module_alias mod, name if mod
container.add_module_alias mod, name, @top_level if mod
get_tk # TkNL
break
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_update_aliases_class
n1 = @xref_data.add_module RDoc::NormalClass, 'N1'
n1_k2 = n1.add_module RDoc::NormalClass, 'N2'

n1.add_module_alias n1_k2, 'A1'
n1.add_module_alias n1_k2, 'A1', @top_level

n1_a1_c = n1.constants.find { |c| c.name == 'A1' }
refute_nil n1_a1_c
Expand All @@ -138,7 +138,7 @@ def test_update_aliases_module
n1 = @xref_data.add_module RDoc::NormalModule, 'N1'
n1_n2 = n1.add_module RDoc::NormalModule, 'N2'

n1.add_module_alias n1_n2, 'A1'
n1.add_module_alias n1_n2, 'A1', @top_level

n1_a1_c = n1.constants.find { |c| c.name == 'A1' }
refute_nil n1_a1_c
Expand All @@ -163,7 +163,7 @@ def test_update_aliases_reparent
l1_l2 = l1.add_module RDoc::NormalModule, 'L2'
o1 = @xref_data.add_module RDoc::NormalModule, 'O1'

o1.add_module_alias l1_l2, 'A1'
o1.add_module_alias l1_l2, 'A1', @top_level

o1_a1_c = o1.constants.find { |c| c.name == 'A1' }
refute_nil o1_a1_c
Expand Down
12 changes: 10 additions & 2 deletions test/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ def test_add_module
end

def test_add_module_alias
c3_c4 = @c2.add_module_alias @c2_c3, 'C4'
tl = RDoc::TopLevel.new 'file.rb'

assert_equal @c2.find_module_named('C4'), c3_c4
c3_c4 = @c2.add_module_alias @c2_c3, 'C4', tl

c4 = @c2.find_module_named('C4')
c2_c3_c4 = @c2_c3.find_module_named('C4')

alias_constant = @c2.constants.first

assert_equal c4, c3_c4
assert_equal tl, alias_constant.file
end

def test_add_module_class
Expand Down
2 changes: 1 addition & 1 deletion test/test_rdoc_top_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_class_classes
end

def test_class_complete
@c2.add_module_alias @c2_c3, 'A1'
@c2.add_module_alias @c2_c3, 'A1', @top_level

RDoc::TopLevel.complete :public

Expand Down

0 comments on commit 14c80df

Please sign in to comment.