Sync RDoc 6.14.0

This commit is contained in:
Stan Lo 2025-05-22 22:49:04 +01:00 committed by Takashi Kokubun
parent ca1ea95784
commit 03eb777c69
185 changed files with 2008 additions and 1655 deletions

View file

@ -168,7 +168,7 @@ class RDoc::Parser::C < RDoc::Parser
# Prepares for parsing a C file. See RDoc::Parser#initialize for details on
# the arguments.
def initialize top_level, file_name, content, options, stats
def initialize(top_level, content, options, stats)
super
@known_classes = RDoc::KNOWN_CLASSES.dup
@ -193,7 +193,7 @@ class RDoc::Parser::C < RDoc::Parser
@enclosure_dependencies.extend TSort
def @enclosure_dependencies.tsort_each_node &block
def @enclosure_dependencies.tsort_each_node(&block)
each_key(&block)
rescue TSort::Cyclic => e
cycle_vars = e.message.scan(/"(.*?)"/).flatten
@ -211,7 +211,7 @@ class RDoc::Parser::C < RDoc::Parser
retry
end
def @enclosure_dependencies.tsort_each_child node, &block
def @enclosure_dependencies.tsort_each_child(node, &block)
fetch(node, []).each(&block)
end
end
@ -248,9 +248,7 @@ class RDoc::Parser::C < RDoc::Parser
# method that reference the same function.
def add_alias(var_name, class_obj, old_name, new_name, comment)
al = RDoc::Alias.new '', old_name, new_name, ''
al.singleton = @singleton_classes.key? var_name
al.comment = comment
al = RDoc::Alias.new '', old_name, new_name, comment, singleton: @singleton_classes.key?(var_name)
al.record_location @top_level
class_obj.add_alias al
@stats.add_alias al
@ -521,7 +519,7 @@ class RDoc::Parser::C < RDoc::Parser
# Finds the comment for an alias on +class_name+ from +new_name+ to
# +old_name+
def find_alias_comment class_name, new_name, old_name
def find_alias_comment(class_name, new_name, old_name)
content =~ %r%((?>/\*.*?\*/\s+))
rb_define_alias\(\s*#{Regexp.escape class_name}\s*,
\s*"#{Regexp.escape new_name}"\s*,
@ -539,7 +537,7 @@ class RDoc::Parser::C < RDoc::Parser
# +read+ and +write+ are the read/write flags ('1' or '0'). Either both or
# neither must be provided.
def find_attr_comment var_name, attr_name, read = nil, write = nil
def find_attr_comment(var_name, attr_name, read = nil, write = nil)
attr_name = Regexp.escape attr_name
rw = if read and write then
@ -572,7 +570,7 @@ class RDoc::Parser::C < RDoc::Parser
##
# Generate a Ruby-method table
def gen_body_table file_content
def gen_body_table(file_content)
table = {}
file_content.scan(%r{
((?>/\*.*?\*/\s*)?)
@ -596,7 +594,7 @@ class RDoc::Parser::C < RDoc::Parser
##
# Find the C code corresponding to a Ruby method
def find_body class_name, meth_name, meth_obj, file_content, quiet = false
def find_body(class_name, meth_name, meth_obj, file_content, quiet = false)
if file_content
@body_table ||= {}
@body_table[file_content] ||= gen_body_table file_content
@ -721,7 +719,7 @@ class RDoc::Parser::C < RDoc::Parser
# */
# VALUE cFoo = rb_define_class("Foo", rb_cObject);
def find_class_comment class_name, class_mod
def find_class_comment(class_name, class_mod)
comment = nil
if @content =~ %r%
@ -754,7 +752,7 @@ class RDoc::Parser::C < RDoc::Parser
##
# Generate a const table
def gen_const_table file_content
def gen_const_table(file_content)
table = {}
@content.scan(%r{
(?<doc>(?>^\s*/\*.*?\*/\s+))
@ -808,9 +806,9 @@ class RDoc::Parser::C < RDoc::Parser
##
# Handles modifiers in +comment+ and updates +meth_obj+ as appropriate.
def find_modifiers comment, meth_obj
def find_modifiers(comment, meth_obj)
comment.normalize
comment.extract_call_seq meth_obj
meth_obj.call_seq = comment.extract_call_seq
look_for_directives_in meth_obj, comment
end
@ -818,7 +816,7 @@ class RDoc::Parser::C < RDoc::Parser
##
# Finds a <tt>Document-method</tt> override for +meth_obj+ on +class_name+
def find_override_comment class_name, meth_obj
def find_override_comment(class_name, meth_obj)
name = Regexp.escape meth_obj.name
prefix = Regexp.escape meth_obj.name_prefix
@ -1015,10 +1013,9 @@ class RDoc::Parser::C < RDoc::Parser
type = 'method' # force public
end
meth_obj = RDoc::AnyMethod.new '', meth_name
singleton = singleton || %w[singleton_method module_function].include?(type)
meth_obj = RDoc::AnyMethod.new '', meth_name, singleton: singleton
meth_obj.c_function = function
meth_obj.singleton =
singleton || %w[singleton_method module_function].include?(type)
p_count = Integer(param_count) rescue -1
@ -1063,7 +1060,7 @@ class RDoc::Parser::C < RDoc::Parser
##
# Registers a singleton class +sclass_var+ as a singleton of +class_var+
def handle_singleton sclass_var, class_var
def handle_singleton(sclass_var, class_var)
class_name = @known_classes[class_var]
@known_classes[sclass_var] = class_name
@ -1074,7 +1071,7 @@ class RDoc::Parser::C < RDoc::Parser
# Loads the variable map with the given +name+ from the RDoc::Store, if
# present.
def load_variable_map map_name
def load_variable_map(map_name)
return {} unless files = @store.cache[map_name]
return {} unless name_map = files[@file_name]
@ -1104,7 +1101,7 @@ class RDoc::Parser::C < RDoc::Parser
# This method modifies the +comment+
# Both :main: and :title: directives are deprecated and will be removed in RDoc 7.
def look_for_directives_in context, comment
def look_for_directives_in(context, comment)
@preprocess.handle comment, context do |directive, param|
case directive
when 'main' then
@ -1141,7 +1138,7 @@ class RDoc::Parser::C < RDoc::Parser
# Extracts parameters from the +method_body+ and returns a method
# parameter string. Follows 1.9.3dev's scan-arg-spec, see README.EXT
def rb_scan_args method_body
def rb_scan_args(method_body)
method_body =~ /rb_scan_args\((.*?)\)/m
return '(*args)' unless $1
@ -1252,7 +1249,7 @@ class RDoc::Parser::C < RDoc::Parser
##
# Creates a RDoc::Comment instance.
def new_comment text = nil, location = nil, language = nil
def new_comment(text = nil, location = nil, language = nil)
RDoc::Comment.new(text, location, language).tap do |comment|
comment.format = @markup
end

View file

@ -23,7 +23,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
# Continued function listings are joined together as a single entry.
# Continued descriptions are joined to make a single paragraph.
def continue_entry_body entry_body, continuation
def continue_entry_body(entry_body, continuation)
return unless last = entry_body.last
if last =~ /\)\s*\z/ and continuation =~ /\A\(/ then
@ -41,7 +41,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
##
# Creates an RDoc::Markup::Document given the +groups+ of ChangeLog entries.
def create_document groups
def create_document(groups)
doc = RDoc::Markup::Document.new
doc.omit_headings_below = 2
doc.file = @top_level
@ -63,7 +63,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
# Returns a list of ChangeLog entries an RDoc::Markup nodes for the given
# +entries+.
def create_entries entries
def create_entries(entries)
out = []
entries.each do |entry, items|
@ -80,7 +80,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
# Returns an RDoc::Markup::List containing the given +items+ in the
# ChangeLog
def create_items items
def create_items(items)
list = RDoc::Markup::List.new :NOTE
items.each do |item|
@ -100,7 +100,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
##
# Groups +entries+ by date.
def group_entries entries
def group_entries(entries)
@time_cache ||= {}
entries.group_by do |title, _|
begin
@ -210,8 +210,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
grouped_entries = group_entries entries
doc = create_document grouped_entries
@top_level.comment = doc
comment = RDoc::Comment.new(@content)
comment.document = doc
@top_level.comment = comment
@top_level
end
@ -259,7 +260,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
# RDoc::Parser::ChangeLog::Git::LogEntry list for the given
# +entries+.
def create_entries entries
def create_entries(entries)
# git log entries have no strictly itemized style like the old
# style, just assume Markdown.
entries.map do |commit, entry|
@ -295,7 +296,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
"label-#{commit}"
end
def label context = nil
def label(context = nil)
aref
end
@ -310,7 +311,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
end + " {#{author}}[mailto:#{email}]"
end
def accept visitor
def accept(visitor)
visitor.accept_heading self
begin
if visitor.respond_to?(:code_object=)
@ -327,7 +328,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
end
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
q.group(2, '[log_entry: ', ']') do
q.text commit
q.text ','

View file

@ -18,7 +18,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
attr_accessor :visibility
attr_reader :container, :singleton
def initialize(top_level, file_name, content, options, stats)
def initialize(top_level, content, options, stats)
super
content = handle_tab_width(content)
@ -31,10 +31,21 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
@track_visibility = :nodoc != @options.visibility
@encoding = @options.encoding
@module_nesting = [top_level]
@module_nesting = [[top_level, false]]
@container = top_level
@visibility = :public
@singleton = false
@in_proc_block = false
end
# Suppress `extend` and `include` within block
# because they might be a metaprogramming block
# example: `Module.new { include M }` `M.module_eval { include N }`
def with_in_proc_block
@in_proc_block = true
yield
@in_proc_block = false
end
# Dive into another container
@ -43,28 +54,30 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
old_container = @container
old_visibility = @visibility
old_singleton = @singleton
old_in_proc_block = @in_proc_block
@visibility = :public
@container = container
@singleton = singleton
@in_proc_block = false
unless singleton
@module_nesting.push container
# Need to update module parent chain to emulate Module.nesting.
# This mechanism is inaccurate and needs to be fixed.
container.parent = old_container
end
@module_nesting.push([container, singleton])
yield container
ensure
@container = old_container
@visibility = old_visibility
@singleton = old_singleton
@module_nesting.pop unless singleton
@in_proc_block = old_in_proc_block
@module_nesting.pop
end
# Records the location of this +container+ in the file for this parser and
# adds it to the list of classes and modules in the file.
def record_location container # :nodoc:
def record_location(container) # :nodoc:
case container
when RDoc::ClassModule then
@top_level.add_to_classes_or_modules container
@ -204,6 +217,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
@stats.add_method meth
end
def has_modifier_nodoc?(line_no) # :nodoc:
@modifier_comments[line_no]&.text&.match?(/\A#\s*:nodoc:/)
end
def handle_modifier_directive(code_object, line_no) # :nodoc:
comment = @modifier_comments[line_no]
@preprocess.handle(comment.text, code_object) if comment
@ -272,21 +289,19 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
if attributes
attributes.each do |attr|
a = RDoc::Attr.new(@container, attr, rw, processed_comment)
a = RDoc::Attr.new(@container, attr, rw, processed_comment, singleton: @singleton)
a.store = @store
a.line = line_no
a.singleton = @singleton
record_location(a)
@container.add_attribute(a)
a.visibility = visibility
end
elsif line_no || node
method_name ||= call_node_name_arguments(node).first if is_call_node
meth = RDoc::AnyMethod.new(@container, method_name)
meth.singleton = @singleton || singleton_method
meth = RDoc::AnyMethod.new(@container, method_name, singleton: @singleton || singleton_method)
handle_consecutive_comment_directive(meth, comment)
comment.normalize
comment.extract_call_seq(meth)
meth.call_seq = comment.extract_call_seq
meth.comment = comment
if node
tokens = visible_tokens_from_location(node.location)
@ -299,7 +314,6 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
meth,
line_no: line_no,
visibility: visibility,
singleton: @singleton || singleton_method,
params: '()',
calls_super: false,
block_params: nil,
@ -435,8 +449,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
comment = consecutive_comment(line_no)
handle_consecutive_comment_directive(@container, comment)
visibility = @container.find_method(old_name, @singleton)&.visibility || :public
a = RDoc::Alias.new(nil, old_name, new_name, comment, @singleton)
a.comment = comment
a = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton)
handle_modifier_directive(a, line_no)
a.store = @store
a.line = line_no
@ -455,10 +468,9 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
return unless @container.document_children
names.each do |symbol|
a = RDoc::Attr.new(nil, symbol.to_s, rw, comment)
a = RDoc::Attr.new(nil, symbol.to_s, rw, comment, singleton: @singleton)
a.store = @store
a.line = line_no
a.singleton = @singleton
record_location(a)
handle_modifier_directive(a, line_no)
@container.add_attribute(a) if should_document?(a)
@ -467,6 +479,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
end
def add_includes_extends(names, rdoc_class, line_no) # :nodoc:
return if @in_proc_block
comment = consecutive_comment(line_no)
handle_consecutive_comment_directive(@container, comment)
names.each do |name|
@ -492,51 +505,53 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
# Adds a method defined by `def` syntax
def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, end_line:)
def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, args_end_line:, end_line:)
return if @in_proc_block
receiver = receiver_name ? find_or_create_module_path(receiver_name, receiver_fallback_type) : @container
meth = RDoc::AnyMethod.new(nil, name)
meth = RDoc::AnyMethod.new(nil, name, singleton: singleton)
if (comment = consecutive_comment(start_line))
handle_consecutive_comment_directive(@container, comment)
handle_consecutive_comment_directive(meth, comment)
comment.normalize
comment.extract_call_seq(meth)
meth.call_seq = comment.extract_call_seq
meth.comment = comment
end
handle_modifier_directive(meth, start_line)
handle_modifier_directive(meth, args_end_line)
handle_modifier_directive(meth, end_line)
return unless should_document?(meth)
if meth.name == 'initialize' && !singleton
if meth.dont_rename_initialize
visibility = :protected
else
meth.name = 'new'
singleton = true
visibility = :public
end
end
internal_add_method(
receiver,
meth,
line_no: start_line,
visibility: visibility,
singleton: singleton,
params: params,
calls_super: calls_super,
block_params: block_params,
tokens: tokens
)
# Rename after add_method to register duplicated 'new' and 'initialize'
# defined in c and ruby just like the old parser did.
if meth.name == 'initialize' && !singleton
if meth.dont_rename_initialize
meth.visibility = :protected
else
meth.name = 'new'
meth.singleton = true
meth.visibility = :public
end
end
end
private def internal_add_method(container, meth, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:) # :nodoc:
private def internal_add_method(container, meth, line_no:, visibility:, params:, calls_super:, block_params:, tokens:) # :nodoc:
meth.name ||= meth.call_seq[/\A[^()\s]+/] if meth.call_seq
meth.name ||= 'unknown'
meth.store = @store
meth.line = line_no
meth.singleton = singleton
container.add_method(meth) # should add after setting singleton and before setting visibility
meth.visibility = visibility
meth.params ||= params
@ -565,12 +580,17 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
if root_name.empty?
mod = @top_level
else
@module_nesting.reverse_each do |nesting|
@module_nesting.reverse_each do |nesting, singleton|
next if singleton
mod = nesting.find_module_named(root_name)
break if mod
# If a constant is found and it is not a module or class, RDoc can't document about it.
# Return an anonymous module to avoid wrong document creation.
return RDoc::NormalModule.new(nil) if nesting.find_constant_named(root_name)
end
return mod || add_module.call(@top_level, root_name, create_mode) unless name
mod ||= add_module.call(@top_level, root_name, :module)
last_nesting, = @module_nesting.reverse_each.find { |_, singleton| !singleton }
return mod || add_module.call(last_nesting, root_name, create_mode) unless name
mod ||= add_module.call(last_nesting, root_name, :module)
end
path.each do |name|
mod = mod.find_module_named(name) || add_module.call(mod, name, :module)
@ -584,7 +604,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
owner_name, path = constant_path.split('::', 2)
return constant_path if owner_name.empty? # ::Foo, ::Foo::Bar
mod = nil
@module_nesting.reverse_each do |nesting|
@module_nesting.reverse_each do |nesting, singleton|
next if singleton
mod = nesting.find_module_named(owner_name)
break if mod
end
@ -598,7 +619,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
def find_or_create_constant_owner_name(constant_path)
const_path, colon, name = constant_path.rpartition('::')
if colon.empty? # class Foo
[@container, name]
# Within `class C` or `module C`, owner is C(== current container)
# Within `class <<C`, owner is C.singleton_class
# but RDoc don't track constants of a singleton class of module
[(@singleton ? nil : @container), name]
elsif const_path.empty? # class ::Foo
[@top_level, name]
else # `class Foo::Bar` or `class ::Foo::Bar`
@ -612,6 +636,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
comment = consecutive_comment(start_line)
handle_consecutive_comment_directive(@container, comment)
owner, name = find_or_create_constant_owner_name(constant_name)
return unless owner
constant = RDoc::Constant.new(name, rhs_name, comment)
constant.store = @store
constant.line = start_line
@ -635,24 +661,29 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
# Adds module or class
def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil)
def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil, superclass_expr: nil)
comment = consecutive_comment(start_line)
handle_consecutive_comment_directive(@container, comment)
return unless @container.document_children
owner, name = find_or_create_constant_owner_name(module_name)
if is_class
mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || '::Object')
return unless owner
if is_class
# RDoc::NormalClass resolves superclass name despite of the lack of module nesting information.
# We need to fix it when RDoc::NormalClass resolved to a wrong constant name
if superclass_name
superclass_full_path = resolve_constant_path(superclass_name)
superclass = @store.find_class_or_module(superclass_full_path) if superclass_full_path
superclass_full_path ||= superclass_name
superclass_full_path = superclass_full_path.sub(/^::/, '')
end
# add_class should be done after resolving superclass
mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || superclass_expr || '::Object')
if superclass_name
if superclass
mod.superclass = superclass
elsif mod.superclass.is_a?(String) && mod.superclass != superclass_full_path
elsif (mod.superclass.is_a?(String) || mod.superclass.name == 'Object') && mod.superclass != superclass_full_path
mod.superclass = superclass_full_path
end
end
@ -676,6 +707,20 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
@store = store
end
def visit_if_node(node)
if node.end_keyword
super
else
# Visit with the order in text representation to handle this method comment
# # comment
# def f
# end if call_node
node.statements.accept(self)
node.predicate.accept(self)
end
end
alias visit_unless_node visit_if_node
def visit_call_node(node)
@scanner.process_comments_until(node.location.start_line - 1)
if node.receiver.nil?
@ -713,6 +758,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
when :private_class_method
_visit_call_public_private_class_method(node, :private) { super }
else
node.arguments&.accept(self)
super
end
else
@ -720,6 +766,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
end
end
def visit_block_node(node)
@scanner.with_in_proc_block do
# include, extend and method definition inside block are not documentable
super
end
end
def visit_alias_method_node(node)
@scanner.process_comments_until(node.location.start_line - 1)
return unless node.old_name.is_a?(Prism::SymbolNode) && node.new_name.is_a?(Prism::SymbolNode)
@ -727,12 +780,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
end
def visit_module_node(node)
node.constant_path.accept(self)
@scanner.process_comments_until(node.location.start_line - 1)
module_name = constant_path_string(node.constant_path)
mod = @scanner.add_module_or_class(module_name, node.location.start_line, node.location.end_line) if module_name
if mod
@scanner.with_container(mod) do
super
node.body&.accept(self)
@scanner.process_comments_until(node.location.end_line)
end
else
@ -741,13 +795,16 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
end
def visit_class_node(node)
node.constant_path.accept(self)
node.superclass&.accept(self)
@scanner.process_comments_until(node.location.start_line - 1)
superclass_name = constant_path_string(node.superclass) if node.superclass
superclass_expr = node.superclass.slice if node.superclass && !superclass_name
class_name = constant_path_string(node.constant_path)
klass = @scanner.add_module_or_class(class_name, node.location.start_line, node.location.end_line, is_class: true, superclass_name: superclass_name) if class_name
klass = @scanner.add_module_or_class(class_name, node.location.start_line, node.location.end_line, is_class: true, superclass_name: superclass_name, superclass_expr: superclass_expr) if class_name
if klass
@scanner.with_container(klass) do
super
node.body&.accept(self)
@scanner.process_comments_until(node.location.end_line)
end
else
@ -758,6 +815,12 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
def visit_singleton_class_node(node)
@scanner.process_comments_until(node.location.start_line - 1)
if @scanner.has_modifier_nodoc?(node.location.start_line)
# Skip visiting inside the singleton class. Also skips creation of node.expression as a module
@scanner.skip_comments_until(node.location.end_line)
return
end
expression = node.expression
expression = expression.body.body.first if expression.is_a?(Prism::ParenthesesNode) && expression.body&.body&.size == 1
@ -772,9 +835,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
when Prism::SelfNode
mod = @scanner.container if @scanner.container != @top_level
end
expression.accept(self)
if mod
@scanner.with_container(mod, singleton: true) do
super
node.body&.accept(self)
@scanner.process_comments_until(node.location.end_line)
end
else
@ -784,6 +848,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
def visit_def_node(node)
start_line = node.location.start_line
args_end_line = node.parameters&.location&.end_line || start_line
end_line = node.location.end_line
@scanner.process_comments_until(start_line - 1)
@ -834,6 +899,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
calls_super: calls_super,
tokens: tokens,
start_line: start_line,
args_end_line: args_end_line,
end_line: end_line
)
ensure
@ -942,7 +1008,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
@scanner.visibility = visibility
else # `public :foo, :bar`, `private def foo; end`
yield
names = visibility_method_arguments(call_node, singleton: @scanner.singleton)
names = visibility_method_arguments(call_node, singleton: false)
@scanner.change_method_visibility(names, visibility) if names
end
end

View file

@ -170,7 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Creates a new Ruby parser.
def initialize(top_level, file_name, content, options, stats)
def initialize(top_level, content, options, stats)
super
content = handle_tab_width(content)
@ -200,7 +200,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Retrieves the read token stream and replaces +pattern+ with +replacement+
# using gsub. If the result is only a ";" returns an empty string.
def get_tkread_clean pattern, replacement # :nodoc:
def get_tkread_clean(pattern, replacement) # :nodoc:
read = get_tkread.gsub(pattern, replacement).strip
return '' if read == ';'
read
@ -214,7 +214,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# +singleton+ if the methods following should be converted to singleton
# methods.
def get_visibility_information tk, single # :nodoc:
def get_visibility_information(tk, single) # :nodoc:
vis_type = tk[:text]
singleton = single == SINGLE
@ -292,8 +292,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Creates a new attribute in +container+ with +name+.
def create_attr container, single, name, rw, comment # :nodoc:
att = RDoc::Attr.new get_tkread, name, rw, comment, single == SINGLE
def create_attr(container, single, name, rw, comment) # :nodoc:
att = RDoc::Attr.new get_tkread, name, rw, comment, singleton: single == SINGLE
record_location att
container.add_attribute att
@ -306,7 +306,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Creates a module alias in +container+ at +rhs_name+ (or at the top-level
# for "::") with the name from +constant+.
def create_module_alias container, constant, rhs_name # :nodoc:
def create_module_alias(container, constant, rhs_name) # :nodoc:
mod = if rhs_name =~ /^::/ then
@store.find_class_or_module rhs_name
else
@ -346,7 +346,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# with :: separated named) and return the ultimate name, the associated
# container, and the given name (with the ::).
def get_class_or_module container, ignore_constants = false
def get_class_or_module(container, ignore_constants = false)
skip_tkspace
name_t = get_tk
given_name = ''.dup
@ -564,7 +564,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# We see the RPAREN as the next token, so we need to exit early. This still
# won't catch all cases (such as "a = yield + 1"
def get_end_token tk # :nodoc:
def get_end_token(tk) # :nodoc:
case tk[:kind]
when :on_lparen
token = RDoc::Parser::RipperStateLex::Token.new
@ -584,7 +584,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Retrieves the method container for a singleton method.
def get_method_container container, name_t # :nodoc:
def get_method_container(container, name_t) # :nodoc:
prev_container = container
container = container.find_module_named(name_t[:text])
@ -652,7 +652,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Marks containers between +container+ and +ancestor+ as ignored
def suppress_parents container, ancestor # :nodoc:
def suppress_parents(container, ancestor) # :nodoc:
while container and container != ancestor do
container.suppress unless container.documented?
container = container.parent
@ -667,7 +667,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
#
# This routine modifies its +comment+ parameter.
def look_for_directives_in container, comment
def look_for_directives_in(container, comment)
@preprocess.handle comment, container do |directive, param|
case directive
when 'method', 'singleton-method',
@ -687,7 +687,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Adds useful info about the parser to +message+
def make_message message
def make_message(message)
prefix = "#{@file_name}:".dup
tk = peek_tk
@ -699,7 +699,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Creates a comment with the correct format
def new_comment comment, line_no = nil
def new_comment(comment, line_no = nil)
c = RDoc::Comment.new comment, @top_level, :ruby
c.line = line_no
c.format = @markup
@ -792,8 +792,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
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, singleton: single == SINGLE)
record_location al
al.line = line_no
@ -852,7 +851,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses a class in +context+ with +comment+
def parse_class container, single, tk, comment
def parse_class(container, single, tk, comment)
line_no = tk[:line_no]
declaration_context = container
@ -886,8 +885,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses and creates a regular class
def parse_class_regular container, declaration_context, single, # :nodoc:
name_t, given_name, comment
def parse_class_regular(container, declaration_context, single, # :nodoc:
name_t, given_name, comment)
superclass = '::Object'
if given_name =~ /^::/ then
@ -926,7 +925,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses a singleton class in +container+ with the given +name+ and
# +comment+.
def parse_class_singleton container, name, comment # :nodoc:
def parse_class_singleton(container, name, comment) # :nodoc:
other = @store.find_class_named name
unless other then
@ -965,7 +964,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses a constant in +context+ with +comment+. If +ignore_constants+ is
# true, no found constants will be added to RDoc.
def parse_constant container, tk, comment, ignore_constants = false
def parse_constant(container, tk, comment, ignore_constants = false)
line_no = tk[:line_no]
name = tk[:text]
@ -1032,7 +1031,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
true
end
def parse_constant_body container, constant, is_array_or_hash # :nodoc:
def parse_constant_body(container, constant, is_array_or_hash) # :nodoc:
nest = 0
rhs_name = ''.dup
@ -1091,7 +1090,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Generates an RDoc::Method or RDoc::Attr from +comment+ by looking for
# :method: or :attr: directives in +comment+.
def parse_comment container, tk, comment
def parse_comment(container, tk, comment)
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
column = tk[:char_no]
line_no = comment.line.nil? ? tk[:line_no] : comment.line
@ -1119,7 +1118,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parse a comment that is describing an attribute in +container+ with the
# given +name+ and +comment+.
def parse_comment_attr container, type, name, comment # :nodoc:
def parse_comment_attr(container, type, name, comment) # :nodoc:
return if name.empty?
rw = case type
@ -1131,8 +1130,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
create_attr container, NORMAL, name, rw, comment
end
def parse_comment_ghost container, text, name, column, line_no, # :nodoc:
comment
def parse_comment_ghost(container, text, name, column, line_no, # :nodoc:
comment)
name = nil if name.empty?
meth = RDoc::GhostMethod.new get_tkread, name
@ -1153,7 +1152,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
comment.normalize
comment.extract_call_seq meth
meth.call_seq = comment.extract_call_seq
return unless meth.name
@ -1170,7 +1169,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Creates an RDoc::Method on +container+ from +comment+ if there is a
# Signature section in the comment
def parse_comment_tomdoc container, tk, comment
def parse_comment_tomdoc(container, tk, comment)
return unless signature = RDoc::TomDoc.signature(comment)
column = tk[:char_no]
line_no = tk[:line_no]
@ -1205,7 +1204,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses an +include+ or +extend+, indicated by the +klass+ and adds it to
# +container+ # with +comment+
def parse_extend_or_include klass, container, comment # :nodoc:
def parse_extend_or_include(klass, container, comment) # :nodoc:
loop do
skip_tkspace_comment
@ -1225,7 +1224,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses an +included+ with a block feature of ActiveSupport::Concern.
def parse_included_with_activesupport_concern container, comment # :nodoc:
def parse_included_with_activesupport_concern(container, comment) # :nodoc:
skip_tkspace_without_nl
tk = get_tk
unless tk[:kind] == :on_lbracket || (tk[:kind] == :on_kw && tk[:text] == 'do')
@ -1243,7 +1242,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
#
# Returns true if the comment was not consumed.
def parse_identifier container, single, tk, comment # :nodoc:
def parse_identifier(container, single, tk, comment) # :nodoc:
case tk[:text]
when 'private', 'protected', 'public', 'private_class_method',
'public_class_method', 'module_function' then
@ -1358,10 +1357,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
return unless name
meth = RDoc::MetaMethod.new get_tkread, name
meth = RDoc::MetaMethod.new get_tkread, name, singleton: singleton
record_location meth
meth.line = line_no
meth.singleton = singleton
remove_token_listener self
@ -1387,7 +1385,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# determine the name while +tk+ is used in an error message if the name
# cannot be determined.
def parse_meta_method_name comment, tk # :nodoc:
def parse_meta_method_name(comment, tk) # :nodoc:
if comment.text.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
return $1 unless $1.empty?
end
@ -1411,13 +1409,13 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses the parameters and block for a meta-programmed method.
def parse_meta_method_params container, single, meth, tk, comment # :nodoc:
def parse_meta_method_params(container, single, meth, tk, comment) # :nodoc:
token_listener meth do
meth.params = ''
look_for_directives_in meth, comment
comment.normalize
comment.extract_call_seq meth
meth.call_seq = comment.extract_call_seq
container.add_method meth
@ -1461,9 +1459,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
return unless name
meth = RDoc::AnyMethod.new get_tkread, name
meth = RDoc::AnyMethod.new get_tkread, name, singleton: single == SINGLE ? true : singleton
look_for_directives_in meth, comment
meth.singleton = single == SINGLE ? true : singleton
if singleton
# `current_line_visibility' is useless because it works against
# the normal method named as same as the singleton method, after
@ -1485,7 +1482,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
parse_method_params_and_body container, single, meth, added_container
comment.normalize
comment.extract_call_seq meth
meth.call_seq = comment.extract_call_seq
meth.comment = comment
@ -1498,7 +1495,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses the parameters and body of +meth+
def parse_method_params_and_body container, single, meth, added_container
def parse_method_params_and_body(container, single, meth, added_container)
token_listener meth do
parse_method_parameters meth
@ -1528,7 +1525,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses a method that needs to be ignored.
def parse_method_dummy container
def parse_method_dummy(container)
dummy = RDoc::Context.new
dummy.parent = container
dummy.store = container.store
@ -1541,7 +1538,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Returns the method name, the container it is in (for def Foo.name) and if
# it is a singleton or regular method.
def parse_method_name container # :nodoc:
def parse_method_name(container) # :nodoc:
skip_tkspace
name_t = get_tk
back_tk = skip_tkspace_without_nl
@ -1568,7 +1565,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# For the given +container+ and initial name token +name_t+ the method name
# is parsed from the token stream for a regular method.
def parse_method_name_regular container, name_t # :nodoc:
def parse_method_name_regular(container, name_t) # :nodoc:
if :on_op == name_t[:kind] && (%w{* & [] []= <<}.include?(name_t[:text])) then
name_t[:text]
else
@ -1586,7 +1583,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# and the new +container+ (if necessary) are parsed from the token stream
# for a singleton method.
def parse_method_name_singleton container, name_t # :nodoc:
def parse_method_name_singleton(container, name_t) # :nodoc:
skip_tkspace
name_t2 = get_tk
@ -1697,7 +1694,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
#
# and add this as the block_params for the method
def parse_method_parameters method
def parse_method_parameters(method)
res = parse_method_or_yield_parameters method
res = "(#{res})" unless res =~ /\A\(/
@ -1712,7 +1709,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses an RDoc::NormalModule in +container+ with +comment+
def parse_module container, single, tk, comment
def parse_module(container, single, tk, comment)
container, name_t, = get_class_or_module container
name = name_t[:text]
@ -1992,7 +1989,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses up to +no+ symbol arguments surrounded by () and places them in
# +args+.
def parse_symbol_arg_paren no # :nodoc:
def parse_symbol_arg_paren(no) # :nodoc:
args = []
loop do
@ -2020,7 +2017,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses up to +no+ symbol arguments separated by spaces and places them in
# +args+.
def parse_symbol_arg_space no, tk # :nodoc:
def parse_symbol_arg_space(no, tk) # :nodoc:
args = []
unget_tk tk
@ -2068,7 +2065,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Parses statements in the top-level +container+
def parse_top_level_statements container
def parse_top_level_statements(container)
comment = collect_first_comment
look_for_directives_in container, comment
@ -2146,7 +2143,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# the name is in +allowed+. A directive can be found anywhere up to the end
# of the current line.
def read_directive allowed
def read_directive(allowed)
tokens = []
while tk = get_tk do
@ -2178,7 +2175,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
#
# See also RDoc::Markup::PreProcess#handle_directive
def read_documentation_modifiers context, allowed
def read_documentation_modifiers(context, allowed)
skip_tkspace_without_nl
directive, value = read_directive allowed
@ -2197,7 +2194,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Records the location of this +container+ in the file for this parser and
# adds it to the list of classes and modules in the file.
def record_location container # :nodoc:
def record_location(container) # :nodoc:
case container
when RDoc::ClassModule then
@top_level.add_to_classes_or_modules container
@ -2308,7 +2305,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Skips the next method in +container+
def skip_method container
def skip_method(container)
meth = RDoc::AnyMethod.new "", "anon"
parse_method_parameters meth
parse_statements container, false, meth
@ -2329,7 +2326,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Updates visibility in +container+ from +vis_type+ and +vis+.
def update_visibility container, vis_type, vis, singleton # :nodoc:
def update_visibility(container, vis_type, vis, singleton) # :nodoc:
new_methods = []
case vis_type
@ -2374,7 +2371,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Prints +message+ to +$stderr+ unless we're being quiet
def warn message
def warn(message)
@options.warn make_message message
end

View file

@ -14,7 +14,7 @@ class RDoc::Parser::Simple < RDoc::Parser
##
# Prepare to parse a plain file
def initialize(top_level, file_name, content, options, stats)
def initialize(top_level, content, options, stats)
super
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
@ -38,7 +38,7 @@ class RDoc::Parser::Simple < RDoc::Parser
##
# Removes the encoding magic comment from +text+
def remove_coding_comment text
def remove_coding_comment(text)
text.sub(/\A# .*coding[=:].*$/, '')
end
@ -49,7 +49,7 @@ class RDoc::Parser::Simple < RDoc::Parser
# dashes at the beginning of the line. Three or more dashes are considered
# to be a rule and ignored.
def remove_private_comment comment
def remove_private_comment(comment)
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
empty = ''
empty = RDoc::Encoding.change_encoding empty, comment.encoding