lib/rdoc/any_method.rb in rdoc-3.12.2 vs lib/rdoc/any_method.rb in rdoc-4.0.0.preview2

- old
+ new

@@ -1,12 +1,19 @@ ## # AnyMethod is the base class for objects representing methods class RDoc::AnyMethod < RDoc::MethodAttr - MARSHAL_VERSION = 1 # :nodoc: + ## + # 2:: + # RDoc 4 + # Added calls_super + # Added parent name and class + # Added section title + MARSHAL_VERSION = 2 # :nodoc: + ## # Don't rename \#initialize to \::new attr_accessor :dont_rename_initialize @@ -23,10 +30,15 @@ ## # Parameters for this method attr_accessor :params + ## + # If true this method uses +super+ to call a superclass version + + attr_accessor :calls_super + include RDoc::TokenStream ## # Creates a new AnyMethod with a token stream +text+ and +name+ @@ -34,10 +46,12 @@ super @c_function = nil @dont_rename_initialize = false @token_stream = nil + @calls_super = false + @superclass_method = nil end ## # Adds +an_alias+ as an alias for this method in +context+. @@ -91,50 +105,64 @@ parse(@comment), @call_seq, @block_params, aliases, @params, - @file.absolute_name, + @file.relative_name, + @calls_super, + @parent.name, + @parent.class, + @section.title, ] end ## # Loads this AnyMethod from +array+. For a loaded AnyMethod the following # methods will return cached values: # # * #full_name # * #parent_name - def marshal_load(array) + def marshal_load array @dont_rename_initialize = nil @is_alias_for = nil @token_stream = nil @aliases = [] + @parent = nil + @parent_name = nil + @parent_class = nil + @section = nil + @file = nil - version = array[0] - @name = array[1] - @full_name = array[2] - @singleton = array[3] - @visibility = array[4] - @comment = array[5] - @call_seq = array[6] - @block_params = array[7] + version = array[0] + @name = array[1] + @full_name = array[2] + @singleton = array[3] + @visibility = array[4] + @comment = array[5] + @call_seq = array[6] + @block_params = array[7] + # 8 handled below + @params = array[9] + # 10 handled below + @calls_super = array[11] + @parent_name = array[12] + @parent_title = array[13] + @section_title = array[14] array[8].each do |new_name, comment| add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton) end - @params = array[9] + @parent_name ||= if @full_name =~ /#/ then + $` + else + name = @full_name.split('::') + name.pop + name.join '::' + end - @parent_name = if @full_name =~ /#/ then - $` - else - name = @full_name.split('::') - name.pop - name.join '::' - end - @file = RDoc::TopLevel.new array[10] if version > 0 end ## # Method name @@ -200,9 +228,35 @@ end params << " { |#{block}| ... }" end params + end + + ## + # Sets the store for this method and its referenced code objects. + + def store= store + super + + @file = @store.add_file @file.full_name if @file + end + + ## + # For methods that +super+, find the superclass method that would be called. + + def superclass_method + return unless @calls_super + return @superclass_method if @superclass_method + + parent.each_ancestor do |ancestor| + if method = ancestor.method_list.find { |m| m.name == @name } then + @superclass_method = method + break + end + end + + @superclass_method end end