diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb index d76ebaf2d0..c7b7f798b1 100644 --- a/lib/rdoc/cross_reference.rb +++ b/lib/rdoc/cross_reference.rb @@ -127,23 +127,41 @@ def resolve name, text if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then type = $2 - type = '' if type == '.' # will find either #method or ::method - method = "#{type}#{$3}" + if '.' == type # will find either #method or ::method + method = $3 + else + method = "#{type}#{$3}" + end container = @context.find_symbol_module($1) elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then type = $1 - type = '' if type == '.' - method = "#{type}#{$2}" + if '.' == type + method = $2 + else + method = "#{type}#{$2}" + end container = @context else + type = nil container = nil end if container then - ref = container.find_local_symbol method - - unless ref || RDoc::TopLevel === container then - ref = container.find_ancestor_local_symbol method + unless RDoc::TopLevel === container then + if '.' == type then + if 'new' == method then # AnyClassName.new will be class method + ref = container.find_local_symbol method + ref = container.find_ancestor_local_symbol method unless ref + else + ref = container.find_local_symbol "::#{method}" + ref = container.find_ancestor_local_symbol "::#{method}" unless ref + ref = container.find_local_symbol "##{method}" unless ref + ref = container.find_ancestor_local_symbol "##{method}" unless ref + end + else + ref = container.find_local_symbol method + ref = container.find_ancestor_local_symbol method unless ref + end end end diff --git a/test/test_rdoc_cross_reference.rb b/test/test_rdoc_cross_reference.rb index a294553704..7a7035a605 100644 --- a/test/test_rdoc_cross_reference.rb +++ b/test/test_rdoc_cross_reference.rb @@ -139,6 +139,15 @@ def test_resolve_method assert_ref @c2_c3_m, '::C2::C3#m(*)' end + def test_resolve_the_same_name_in_instance_and_class_method + assert_ref @c9_a_i_foo, 'C9::A#foo' + assert_ref @c9_a_c_bar, 'C9::A::bar' + assert_ref @c9_b_c_foo, 'C9::B::foo' + assert_ref @c9_b_i_bar, 'C9::B#bar' + assert_ref @c9_b_c_foo, 'C9::B.foo' + assert_ref @c9_a_c_bar, 'C9::B.bar' + end + def test_resolve_method_equals3 m = RDoc::AnyMethod.new '', '===' @c1.add_method m diff --git a/test/test_rdoc_store.rb b/test/test_rdoc_store.rb index 4246b4cbbf..e5cf75203f 100644 --- a/test/test_rdoc_store.rb +++ b/test/test_rdoc_store.rb @@ -162,7 +162,7 @@ def test_add_file_relative def test_all_classes_and_modules expected = %w[ - C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C8::S1 + C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C8::S1 C9 C9::A C9::B Child M1 M1::M2 Parent @@ -213,7 +213,7 @@ def test_class_path def test_classes expected = %w[ - C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C8::S1 + C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C8::S1 C9 C9::A C9::B Child Parent ] diff --git a/test/xref_data.rb b/test/xref_data.rb index d002b422f9..77380aa868 100644 --- a/test/xref_data.rb +++ b/test/xref_data.rb @@ -101,6 +101,18 @@ class S1 end end +class C9 + class A + def foo() end + def self.bar() end + end + + class B < A + def self.foo() end + def bar() end + end +end + module M1 def m end diff --git a/test/xref_test_case.rb b/test/xref_test_case.rb index 70b7df4222..28b03e89cd 100644 --- a/test/xref_test_case.rb +++ b/test/xref_test_case.rb @@ -56,6 +56,14 @@ def generator.file_dir() nil end @c8 = @xref_data.find_module_named 'C8' @c8_s1 = @xref_data.find_module_named 'C8::S1' + @c9 = @xref_data.find_module_named 'C9' + @c9_a = @xref_data.find_module_named 'C9::A' + @c9_a_i_foo = @c9_a.method_list.first + @c9_a_c_bar = @c9_a.method_list.last + @c9_b = @xref_data.find_module_named 'C9::B' + @c9_b_c_foo = @c9_b.method_list.first + @c9_b_i_bar = @c9_b.method_list.last + @m1 = @xref_data.find_module_named 'M1' @m1_m = @m1.method_list.first