Permalink
Browse files

Move record_location up to RDoc::CodeObject and record locations of a…

…liases
  • Loading branch information...
1 parent ce79841 commit 8efdd1b78f147a40c81cb63478aa825360ac6cd4 @drbrain drbrain committed Sep 29, 2010
View
@@ -37,9 +37,9 @@
on how to document source code.
* An RDoc::Require is now always listed at the file level. Patch by Thierry
Lambert.
- * RDoc::MethodAttrs know which file they were defined in.
+ * RDoc::CodeObjects now know which file they were defined in.
* Bug fixes
- * RDoc::Generator tests no longer require installed RDoc on Ruby 1.9
+ * RDoc::Generator tests no longer require any installed RDoc on Ruby 1.9
=== 2.5.11 / 2010-08-20
@@ -51,6 +51,11 @@ class RDoc::CodeObject
attr_reader :done_documenting
##
+ # Which file this code object was defined in
+
+ attr_reader :file
+
+ ##
# Force documentation of this CodeObject
attr_reader :force_documentation
@@ -88,14 +93,14 @@ class RDoc::CodeObject
def initialize
@metadata = {}
@comment = ''
+ @parent = nil
+ @file = nil
@document_children = true
@document_self = true
@done_documenting = false
@force_documentation = false
@received_nodoc = false
-
- @parent = nil
end
##
@@ -181,6 +186,13 @@ def parent_name
end
##
+ # Records the RDoc::TopLevel (file) where this code object was defined
+
+ def record_location top_level
+ @file = top_level
+ end
+
+ ##
# Enable capture of documentation unless documentation has been
# turned off by :endoc:
@@ -28,11 +28,6 @@ class RDoc::MethodAttr < RDoc::CodeObject
attr_reader :text
##
- # Which file this method or attr was defined in
-
- attr_reader :top_level
-
- ##
# Array of other names for this method/attribute
attr_reader :aliases
@@ -207,13 +202,6 @@ def pretty_name
end
##
- # Records the RDoc::TopLevel (file) where this method or attr was defined
-
- def record_location top_level
- @top_level = top_level
- end
-
- ##
# Type of method/attribute (class or instance)
def type
@@ -505,7 +505,10 @@ def parse_alias(context, single, tk, comment)
return
end
- al = RDoc::Alias.new get_tkread, old_name, new_name, comment, single == SINGLE
+ al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
+ single == SINGLE)
+ al.record_location @top_level
+
read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
context.add_alias al if al.document_self
@stats.add_alias al
@@ -0,0 +1,13 @@
+require File.expand_path '../xref_test_case', __FILE__
+
+class TestRDocAlias < XrefTestCase
+
+ def test_to_s
+ a = RDoc::Alias.new nil, 'a', 'b', ''
+ a.parent = @c2
+
+ assert_equal 'alias: b -> #a in: RDoc::NormalClass C2 < Object', a.to_s
+ end
+
+end
+
@@ -124,6 +124,13 @@ def test_received_ndoc
@co.document_self = true
end
+ def test_record_location
+ c = RDoc::CodeObject.new
+ c.record_location @xref_data
+
+ assert_equal 'xref_data.rb', c.file.relative_name
+ end
+
def test_start_doc
@co.document_self = false
@co.document_children = false
@@ -1,11 +1,11 @@
require File.expand_path '../xref_test_case', __FILE__
-class RDocMethodAttr < XrefTestCase
+class TestRDocMethodAttr < XrefTestCase
- def test_record_location
- @c1_m.record_location @xref_data
-
- assert_equal 'xref_data.rb', @c1_m.top_level.relative_name
+ def test_to_s
+ assert_equal 'RDoc::AnyMethod: C1#m', @c1_m.to_s
+ assert_equal 'RDoc::AnyMethod: C2#b', @c2_b.to_s
+ assert_equal 'RDoc::AnyMethod: C1::m', @c1__m.to_s
end
end
@@ -219,10 +219,11 @@ def test_parse_alias
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
- assert_equal 'bar', alas.old_name
- assert_equal 'next=', alas.new_name
- assert_equal klass, alas.parent
- assert_equal 'comment', alas.comment
+ assert_equal 'bar', alas.old_name
+ assert_equal 'next=', alas.new_name
+ assert_equal klass, alas.parent
+ assert_equal 'comment', alas.comment
+ assert_equal @top_level, alas.file
end
def test_parse_alias_singleton
@@ -235,11 +236,12 @@ def test_parse_alias_singleton
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::SINGLE, tk, 'comment'
- assert_equal 'bar', alas.old_name
- assert_equal 'next=', alas.new_name
- assert_equal klass, alas.parent
- assert_equal 'comment', alas.comment
- assert alas.singleton
+ assert_equal 'bar', alas.old_name
+ assert_equal 'next=', alas.new_name
+ assert_equal klass, alas.parent
+ assert_equal 'comment', alas.comment
+ assert_equal @top_level, alas.file
+ assert alas.singleton
end
def test_parse_alias_meta
@@ -272,7 +274,7 @@ def test_parse_attr
foo = klass.attributes.first
assert_equal 'foo', foo.name
assert_equal 'my attr', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_attr_accessor
@@ -293,7 +295,7 @@ def test_parse_attr_accessor
assert_equal 'foo', foo.name
assert_equal 'RW', foo.rw
assert_equal 'my attr', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
bar = klass.attributes.last
assert_equal 'bar', bar.name
@@ -334,7 +336,7 @@ def test_parse_attr_accessor_writer
assert_equal 'foo', foo.name
assert_equal 'W', foo.rw
assert_equal "my attr", foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
bar = klass.attributes.last
assert_equal 'bar', bar.name
@@ -359,7 +361,7 @@ def test_parse_meta_attr
assert_equal 'foo', foo.name
assert_equal 'RW', foo.rw
assert_equal "my method", foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_attr_accessor
@@ -379,7 +381,7 @@ def test_parse_meta_attr_accessor
assert_equal 'foo', foo.name
assert_equal 'RW', foo.rw
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_attr_named
@@ -399,7 +401,7 @@ def test_parse_meta_attr_named
assert_equal 'foo', foo.name
assert_equal 'RW', foo.rw
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_attr_reader
@@ -418,7 +420,7 @@ def test_parse_meta_attr_reader
assert_equal 'foo', foo.name
assert_equal 'R', foo.rw
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_attr_writer
@@ -437,7 +439,7 @@ def test_parse_meta_attr_writer
assert_equal 'foo', foo.name
assert_equal 'W', foo.rw
assert_equal "my method", foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_class
@@ -472,7 +474,7 @@ class Foo
blah = foo.method_list.first
assert_equal 'Foo#blah', blah.full_name
- assert_equal @top_level, blah.top_level
+ assert_equal @top_level, blah.file
end
def test_parse_class_nested_superclass
@@ -661,7 +663,7 @@ def test_parse_comment_attr
assert_equal 'foo', foo.name
assert_equal 'RW', foo.rw
assert_equal 'my attr', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
assert_equal nil, foo.viewer
assert_equal true, foo.document_children
@@ -690,7 +692,7 @@ def test_parse_comment_method
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
@@ -763,7 +765,7 @@ def test_parse_meta_method
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
@@ -813,7 +815,7 @@ def test_parse_meta_method_name
foo = klass.method_list.first
assert_equal 'woo_hoo!', foo.name
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_method_singleton
@@ -832,7 +834,7 @@ def test_parse_meta_method_singleton
assert_equal 'foo', foo.name
assert_equal true, foo.singleton, 'singleton method'
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_method_singleton_name
@@ -851,7 +853,7 @@ def test_parse_meta_method_singleton_name
assert_equal 'woo_hoo!', foo.name
assert_equal true, foo.singleton, 'singleton method'
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_method_string_name
@@ -867,7 +869,7 @@ def test_parse_meta_method_string_name
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_meta_method_unknown
@@ -883,7 +885,7 @@ def test_parse_meta_method_unknown
foo = klass.method_list.first
assert_equal 'unknown', foo.name
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_method
@@ -901,7 +903,7 @@ def test_parse_method
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal 'my method', foo.comment
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
@@ -1028,7 +1030,7 @@ def test_parse_method_no_parens
foo = klass.method_list.first
assert_equal '(arg1, arg2)', foo.params
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_method_parameters_comment
@@ -1078,7 +1080,7 @@ def test_parse_method_toplevel
foo = object.method_list.first
assert_equal 'Object#foo', foo.full_name
- assert_equal @top_level, foo.top_level
+ assert_equal @top_level, foo.file
end
def test_parse_method_toplevel_class
View
@@ -13,9 +13,15 @@ def self.m
def m foo
end
+
end
class C2
+ def b
+ end
+
+ alias a b
+
class C3
def m
end
@@ -38,7 +38,11 @@ def generator.file_dir() nil end
@c1_m = @c1.method_list.last # C1#m
@c1__m = @c1.method_list.first # C1::m
+
@c2 = @xref_data.find_module_named 'C2'
+ @c2_a = @c2.method_list.last
+ @c2_b = @c2.method_list.first
+
@c2_c3 = @xref_data.find_module_named 'C2::C3'
@c3 = @xref_data.find_module_named 'C3'
@c4 = @xref_data.find_module_named 'C4'

0 comments on commit 8efdd1b

Please sign in to comment.