Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/code_object/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def marshal_load(array)
@name = array[1]
@full_name = array[2]
@singleton = array[3]
@visibility = array[4]
@visibility = array[4] || :public
@comment = RDoc::Comment.from_document array[5]
@call_seq = array[6]
@block_params = array[7]
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/code_object/attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def marshal_load(array)
@name = array[1]
@full_name = array[2]
@rw = array[3]
@visibility = array[4]
@visibility = array[4] || :public
@comment = RDoc::Comment.from_document array[5]
@singleton = array[6] || false # MARSHAL_VERSION == 0
# 7 handled below
Expand Down
8 changes: 1 addition & 7 deletions lib/rdoc/code_object/class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def self.from_module(class_type, mod)
klass.sections.concat mod.sections
klass.unmatched_alias_lists = mod.unmatched_alias_lists
klass.current_section = mod.current_section
klass.visibility = mod.visibility

klass.classes_hash.update mod.classes_hash
klass.modules_hash.update mod.modules_hash
Expand Down Expand Up @@ -397,7 +396,6 @@ def marshal_load(array) # :nodoc:
@done_documenting = false
@parent = nil
@temporary_section = nil
@visibility = nil
@classes = {}
@modules = {}

Expand Down Expand Up @@ -442,11 +440,10 @@ def marshal_load(array) # :nodoc:

array[8].each do |type, visibilities|
visibilities.each do |visibility, methods|

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add method.visibility = visibility and a test for it

@visibility = visibility

methods.each do |name, file|
method = RDoc::AnyMethod.new name, singleton: type == 'class'
method.record_location RDoc::TopLevel.new file
method.visibility = visibility
add_method method
end
end
Expand Down Expand Up @@ -972,9 +969,6 @@ def prepare_to_embed(code_object, singleton=false)
code_object.mixin_from = code_object.parent
code_object.singleton = true if singleton
set_current_section(code_object.section.title, code_object.section.comment)
# add_method and add_attribute will reassign self's visibility back to the method/attribute
# so we need to sync self's visibility with the object's to properly retain that information
self.visibility = code_object.visibility
code_object
end
end
25 changes: 0 additions & 25 deletions lib/rdoc/code_object/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ class RDoc::Context < RDoc::CodeObject

attr_reader :external_aliases

##
# Current visibility of this context

attr_accessor :visibility

##
# Current visibility of this line

attr_writer :current_line_visibility

##
# Hash of registered methods. Attributes are also registered here,
# twice if they are RW.
Expand All @@ -127,7 +117,6 @@ def initialize

@name ||= "unknown"
@parent = nil
Comment on lines 118 to 119
@visibility = :public

@current_section = Section.new self, nil, nil
@sections = { nil => @current_section }
Expand All @@ -151,7 +140,6 @@ def initialize_methods_etc
@extends = []
@constants = []
@external_aliases = []
@current_line_visibility = nil

# This Hash maps a method name to a list of unmatched aliases (aliases of
# a method not yet encountered).
Expand Down Expand Up @@ -262,7 +250,6 @@ def add_attribute(attribute)
end

if register
attribute.visibility = @visibility
add_to @attributes, attribute
resolve_aliases attribute
end
Expand Down Expand Up @@ -478,11 +465,6 @@ def add_method(method)
end
else
@methods_hash[key] = method
if @current_line_visibility
method.visibility, @current_line_visibility = @current_line_visibility, nil
else
method.visibility = @visibility
end
add_to @method_list, method
resolve_aliases method
end
Expand Down Expand Up @@ -1032,13 +1014,6 @@ def name_for_path
full_name
end

##
# Changes the visibility for new methods to +visibility+

def ongoing_visibility=(visibility)
@visibility = visibility
end

##
# Record +top_level+ as a file +self+ is in.

Expand Down
3 changes: 1 addition & 2 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,9 @@ def handle_method(type, var_name, meth_name, function, param_count,
if meth_obj.section_title
class_obj.temporary_section = class_obj.add_section(meth_obj.section_title)
end
meth_obj.visibility = type == 'private_method' ? :private : :public
class_obj.add_method meth_obj

@stats.add_method meth_obj
meth_obj.visibility = :private if 'private_method' == type
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/parser/rbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def parse_attr_decl(decl, context)
)
record_object_location attribute, decl.location
attribute.type_signature_lines = type_signature_lines
context.add_attribute attribute
attribute.visibility = decl.visibility if decl.visibility
context.add_attribute attribute
end

def parse_class_decl(decl, context)
Expand Down Expand Up @@ -260,8 +260,8 @@ def parse_method_decl(decl, context)
end

method.comment = comment if comment
context.add_method method
method.visibility = visibility if visibility
context.add_method method
end

def parse_module_decl(decl, context)
Expand Down
11 changes: 5 additions & 6 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ def handle_meta_method_comment(comment, directives, node)
a = RDoc::Attr.new(attr, rw, comment, singleton: @singleton)
a.store = @store
a.line = line_no
a.visibility = visibility
record_location(a)
@container.add_attribute(a)
mark_container_documentable(@container)
a.visibility = visibility
end
elsif line_no || node
method_name ||= call_node_name_arguments(node).first if is_call_node
Expand Down Expand Up @@ -576,13 +576,13 @@ def change_method_visibility(names, visibility, singleton: @singleton)
end
end
new_methods.each do |method|
method.visibility = visibility
case method
when RDoc::AnyMethod
@container.add_method(method)
when RDoc::Attr
@container.add_attribute(method)
end
method.visibility = visibility
end
end

Expand All @@ -602,13 +602,13 @@ def change_method_to_module_function(names)
new_methods << s_m
end
new_methods.each do |method|
method.visibility = :public
case method
when RDoc::AnyMethod
@container.add_method(method)
when RDoc::Attr
@container.add_attribute(method)
end
method.visibility = :public
end
end

Expand Down Expand Up @@ -638,7 +638,6 @@ def add_alias_method(old_name, new_name, line_no)
if should_document?(a)
mark_container_documentable(@container)
@container.add_alias(a)
@container.find_method(new_name, @singleton)&.visibility = visibility
end
end

Expand All @@ -656,13 +655,13 @@ def add_attributes(names, rw, line_no)
a.store = @store
a.line = line_no
a.type_signature_lines = type_signature_lines
a.visibility = visibility
record_location(a)
handle_modifier_directive(a, line_no)
if should_document?(a)
@container.add_attribute(a)
mark_container_documentable(@container)
end
a.visibility = visibility # should set after adding to container
end
end

Expand Down Expand Up @@ -743,12 +742,12 @@ def add_method(method_name, receiver_name:, receiver_fallback_type:, visibility:
meth.name ||= 'unknown'
meth.store = @store
meth.line = line_no
container.add_method(meth) # should add after setting singleton and before setting visibility
meth.visibility = visibility
meth.params ||= params || '()'
meth.calls_super = calls_super
meth.block_params ||= block_params if block_params
meth.type_signature_lines = type_signature_lines
container.add_method(meth)
record_location(meth)
meth.start_collecting_tokens(:ruby)
tokens.each do |token|
Expand Down
24 changes: 24 additions & 0 deletions test/rdoc/code_object/class_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,30 @@ def test_marshal_dump_visibility
assert_empty loaded.method_list
end

def test_marshal_load_method_visibility
tl = @store.add_file 'file.rb'
cm = tl.add_class RDoc::NormalClass, 'Klass'
cm.record_location tl

RDoc::VISIBILITIES.each do |visibility|
[false, true].each do |singleton|
m = RDoc::AnyMethod.new "#{visibility}_method", singleton: singleton
m.record_location tl
m.visibility = visibility
cm.add_method m
end
end

loaded = Marshal.load Marshal.dump cm
loaded.store = @store

RDoc::VISIBILITIES.each do |visibility|
[false, true].each do |singleton|
assert_equal visibility, loaded.find_method("#{visibility}_method", singleton).visibility
end
end
end

def test_marshal_load_version_0
tl = @store.add_file 'file.rb'
ns = tl.add_module RDoc::NormalModule, 'Namespace'
Expand Down
4 changes: 0 additions & 4 deletions test/rdoc/rdoc_context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def test_initialize
assert_equal 'unknown', @context.name
assert_equal '', @context.comment
assert_nil @context.parent
assert_equal :public, @context.visibility
assert_equal 1, @context.sections.length
assert_nil @context.temporary_section

Expand Down Expand Up @@ -194,7 +193,6 @@ def test_add_include

def test_add_method
meth = RDoc::AnyMethod.new 'old_name'
meth.visibility = nil

@context.add_method meth

Expand All @@ -221,7 +219,6 @@ def test_add_method_duplicate

meth1 = RDoc::AnyMethod.new 'name'
meth1.record_location @store.add_file 'first.rb'
meth1.visibility = nil
meth1.comment = comment 'first'

@context.add_method meth1
Expand Down Expand Up @@ -249,7 +246,6 @@ def test_add_method_duplicate_loading

meth1 = RDoc::AnyMethod.new 'name'
meth1.record_location @store.add_file 'first.rb'
meth1.visibility = nil
meth1.comment = comment 'first'

@context.add_method meth1
Expand Down
1 change: 0 additions & 1 deletion test/rdoc/rdoc_stats_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def test_report_constant_alias
mod = @tl.add_module RDoc::NormalModule, 'M'

c = @tl.add_class RDoc::NormalClass, 'C'
mod.add_constant c

ca = RDoc::Constant.new 'CA', nil, nil
ca.is_alias_for = c
Expand Down
18 changes: 18 additions & 0 deletions test/rdoc/rdoc_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,24 @@ def test_save_class_merge_constant
assert_empty result.constants
end

def test_save_class_merge_method_visibility
private_meth = RDoc::AnyMethod.new 'private_method'
private_meth.record_location @top_level
private_meth.visibility = :private
@klass.add_method private_meth

@s.save_class @klass
# Second save loads the class saved above and merges @klass into it
@s.save_class @klass

assert_equal :public, @meth.visibility

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure if I understand what this test checks against 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:private case and description added

assert_equal :private, private_meth.visibility

loaded = @s.load_class 'Object'
assert_equal :public, loaded.find_method('method', false).visibility
assert_equal :private, loaded.find_method('private_method', false).visibility
end

def test_save_class_methods
@s.save_class @klass

Expand Down