Class: Spoom::Model::ReferencesVisitor
- Inherits:
-
Visitor
- Object
- Prism::Visitor
- Visitor
- Spoom::Model::ReferencesVisitor
show all
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/model/references_visitor.rb
Overview
Visit a file to collect all the references to constants and methods
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Visitor
#visit_alias_global_variable_node, #visit_alternation_pattern_node, #visit_arguments_node, #visit_array_node, #visit_array_pattern_node, #visit_assoc_node, #visit_assoc_splat_node, #visit_back_reference_read_node, #visit_begin_node, #visit_block_local_variable_node, #visit_block_node, #visit_block_parameter_node, #visit_block_parameters_node, #visit_break_node, #visit_call_target_node, #visit_capture_pattern_node, #visit_case_match_node, #visit_case_node, #visit_child_nodes, #visit_class_variable_and_write_node, #visit_class_variable_operator_write_node, #visit_class_variable_or_write_node, #visit_class_variable_read_node, #visit_class_variable_target_node, #visit_class_variable_write_node, #visit_constant_path_and_write_node, #visit_constant_path_operator_write_node, #visit_constant_path_or_write_node, #visit_constant_path_target_node, #visit_constant_target_node, #visit_def_node, #visit_defined_node, #visit_else_node, #visit_embedded_statements_node, #visit_embedded_variable_node, #visit_ensure_node, #visit_false_node, #visit_find_pattern_node, #visit_flip_flop_node, #visit_float_node, #visit_for_node, #visit_forwarding_arguments_node, #visit_forwarding_parameter_node, #visit_forwarding_super_node, #visit_global_variable_and_write_node, #visit_global_variable_operator_write_node, #visit_global_variable_or_write_node, #visit_global_variable_read_node, #visit_global_variable_target_node, #visit_global_variable_write_node, #visit_hash_node, #visit_hash_pattern_node, #visit_if_node, #visit_imaginary_node, #visit_implicit_node, #visit_implicit_rest_node, #visit_in_node, #visit_index_and_write_node, #visit_index_operator_write_node, #visit_index_or_write_node, #visit_index_target_node, #visit_instance_variable_and_write_node, #visit_instance_variable_operator_write_node, #visit_instance_variable_or_write_node, #visit_instance_variable_read_node, #visit_instance_variable_target_node, #visit_instance_variable_write_node, #visit_integer_node, #visit_interpolated_match_last_line_node, #visit_interpolated_regular_expression_node, #visit_interpolated_string_node, #visit_interpolated_symbol_node, #visit_interpolated_x_string_node, #visit_keyword_hash_node, #visit_keyword_rest_parameter_node, #visit_lambda_node, #visit_local_variable_read_node, #visit_local_variable_target_node, #visit_match_last_line_node, #visit_match_predicate_node, #visit_match_required_node, #visit_match_write_node, #visit_missing_node, #visit_multi_target_node, #visit_next_node, #visit_nil_node, #visit_no_keywords_parameter_node, #visit_numbered_parameters_node, #visit_numbered_reference_read_node, #visit_optional_keyword_parameter_node, #visit_optional_parameter_node, #visit_parameters_node, #visit_parentheses_node, #visit_pinned_expression_node, #visit_pinned_variable_node, #visit_post_execution_node, #visit_pre_execution_node, #visit_program_node, #visit_range_node, #visit_rational_node, #visit_redo_node, #visit_regular_expression_node, #visit_required_keyword_parameter_node, #visit_required_parameter_node, #visit_rescue_modifier_node, #visit_rescue_node, #visit_rest_parameter_node, #visit_retry_node, #visit_return_node, #visit_self_node, #visit_singleton_class_node, #visit_source_encoding_node, #visit_source_file_node, #visit_source_line_node, #visit_splat_node, #visit_statements_node, #visit_string_node, #visit_super_node, #visit_symbol_node, #visit_true_node, #visit_undef_node, #visit_unless_node, #visit_until_node, #visit_when_node, #visit_while_node, #visit_x_string_node, #visit_yield_node
Constructor Details
Returns a new instance of ReferencesVisitor.
14
15
16
17
18
19
|
# File 'lib/spoom/model/references_visitor.rb', line 14
def initialize(file)
super()
@file = file
@references = T.let([], T::Array[Reference])
end
|
Instance Attribute Details
#references ⇒ Object
Returns the value of attribute references.
11
12
13
|
# File 'lib/spoom/model/references_visitor.rb', line 11
def references
@references
end
|
Instance Method Details
#visit_alias_method_node(node) ⇒ Object
22
23
24
|
# File 'lib/spoom/model/references_visitor.rb', line 22
def visit_alias_method_node(node)
reference_method(node.old_name.slice, node)
end
|
#visit_and_node(node) ⇒ Object
27
28
29
30
|
# File 'lib/spoom/model/references_visitor.rb', line 27
def visit_and_node(node)
reference_method(node.operator_loc.slice, node)
super
end
|
#visit_block_argument_node(node) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/spoom/model/references_visitor.rb', line 33
def visit_block_argument_node(node)
expression = node.expression
case expression
when Prism::SymbolNode
reference_method(expression.unescaped, expression)
else
visit(expression)
end
end
|
#visit_call_and_write_node(node) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/spoom/model/references_visitor.rb', line 44
def visit_call_and_write_node(node)
visit(node.receiver)
reference_method(node.read_name.to_s, node)
reference_method(node.write_name.to_s, node)
visit(node.value)
end
|
#visit_call_node(node) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/spoom/model/references_visitor.rb', line 68
def visit_call_node(node)
visit(node.receiver)
name = node.name.to_s
reference_method(name, node)
case name
when "<", ">", "<=", ">="
reference_method("<=>", node)
end
visit(node.arguments)
visit(node.block)
end
|
#visit_call_operator_write_node(node) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/spoom/model/references_visitor.rb', line 52
def visit_call_operator_write_node(node)
visit(node.receiver)
reference_method(node.read_name.to_s, node)
reference_method(node.write_name.to_s, node)
visit(node.value)
end
|
#visit_call_or_write_node(node) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/spoom/model/references_visitor.rb', line 60
def visit_call_or_write_node(node)
visit(node.receiver)
reference_method(node.read_name.to_s, node)
reference_method(node.write_name.to_s, node)
visit(node.value)
end
|
#visit_class_node(node) ⇒ Object
85
86
87
88
|
# File 'lib/spoom/model/references_visitor.rb', line 85
def visit_class_node(node)
visit(node.superclass) if node.superclass
visit(node.body)
end
|
#visit_constant_and_write_node(node) ⇒ Object
91
92
93
94
|
# File 'lib/spoom/model/references_visitor.rb', line 91
def visit_constant_and_write_node(node)
reference_constant(node.name.to_s, node)
visit(node.value)
end
|
#visit_constant_operator_write_node(node) ⇒ Object
97
98
99
100
|
# File 'lib/spoom/model/references_visitor.rb', line 97
def visit_constant_operator_write_node(node)
reference_constant(node.name.to_s, node)
visit(node.value)
end
|
#visit_constant_or_write_node(node) ⇒ Object
103
104
105
106
|
# File 'lib/spoom/model/references_visitor.rb', line 103
def visit_constant_or_write_node(node)
reference_constant(node.name.to_s, node)
visit(node.value)
end
|
#visit_constant_path_node(node) ⇒ Object
109
110
111
112
|
# File 'lib/spoom/model/references_visitor.rb', line 109
def visit_constant_path_node(node)
visit(node.parent)
reference_constant(node.name.to_s, node)
end
|
#visit_constant_path_write_node(node) ⇒ Object
115
116
117
118
|
# File 'lib/spoom/model/references_visitor.rb', line 115
def visit_constant_path_write_node(node)
visit(node.target.parent)
visit(node.value)
end
|
#visit_constant_read_node(node) ⇒ Object
121
122
123
|
# File 'lib/spoom/model/references_visitor.rb', line 121
def visit_constant_read_node(node)
reference_constant(node.name.to_s, node)
end
|
#visit_constant_write_node(node) ⇒ Object
126
127
128
|
# File 'lib/spoom/model/references_visitor.rb', line 126
def visit_constant_write_node(node)
visit(node.value)
end
|
#visit_local_variable_and_write_node(node) ⇒ Object
131
132
133
134
135
136
|
# File 'lib/spoom/model/references_visitor.rb', line 131
def visit_local_variable_and_write_node(node)
name = node.name.to_s
reference_method(name, node)
reference_method("#{name}=", node)
visit(node.value)
end
|
#visit_local_variable_operator_write_node(node) ⇒ Object
139
140
141
142
143
144
|
# File 'lib/spoom/model/references_visitor.rb', line 139
def visit_local_variable_operator_write_node(node)
name = node.name.to_s
reference_method(name, node)
reference_method("#{name}=", node)
visit(node.value)
end
|
#visit_local_variable_or_write_node(node) ⇒ Object
147
148
149
150
151
152
|
# File 'lib/spoom/model/references_visitor.rb', line 147
def visit_local_variable_or_write_node(node)
name = node.name.to_s
reference_method(name, node)
reference_method("#{name}=", node)
visit(node.value)
end
|
#visit_local_variable_write_node(node) ⇒ Object
155
156
157
158
|
# File 'lib/spoom/model/references_visitor.rb', line 155
def visit_local_variable_write_node(node)
reference_method("#{node.name}=", node)
visit(node.value)
end
|
#visit_module_node(node) ⇒ Object
161
162
163
|
# File 'lib/spoom/model/references_visitor.rb', line 161
def visit_module_node(node)
visit(node.body)
end
|
#visit_multi_write_node(node) ⇒ Object
166
167
168
169
170
171
172
173
174
|
# File 'lib/spoom/model/references_visitor.rb', line 166
def visit_multi_write_node(node)
node.lefts.each do |const|
case const
when Prism::LocalVariableTargetNode
reference_method("#{const.name}=", node)
end
end
visit(node.value)
end
|
#visit_or_node(node) ⇒ Object
177
178
179
180
|
# File 'lib/spoom/model/references_visitor.rb', line 177
def visit_or_node(node)
reference_method(node.operator_loc.slice, node)
super
end
|