Class: Yoda::Evaluation::SignatureDiscovery
- Inherits:
-
Object
- Object
- Yoda::Evaluation::SignatureDiscovery
- Defined in:
- lib/yoda/evaluation/signature_discovery.rb
Overview
SignatureDiscovery infers method candidates for the nearest send node and specify the number of index of these parameters. SignatureDiscovery shows help for the current parameter of method candidates.
Instance Attribute Summary collapse
- #location ⇒ Parsing::Location readonly
- #registry ⇒ Store::Registry readonly
- #source ⇒ String readonly
Instance Method Summary collapse
- #index_word ⇒ String?
-
#initialize(registry, source, location) ⇒ SignatureDiscovery
constructor
A new instance of SignatureDiscovery.
- #method_candidates ⇒ Array<Store::Objects::MethodObject>
- #nearest_send_node ⇒ Parsing::NodeObjects::SendNode?
- #receiver_type ⇒ Model::Types::Base
- #send_nodes_to_current_location ⇒ Array<Parsing::NodeObjects::SendNode>
- #valid? ⇒ Boolean
Constructor Details
#initialize(registry, source, location) ⇒ SignatureDiscovery
Returns a new instance of SignatureDiscovery.
18 19 20 21 22 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 18 def initialize(registry, source, location) @registry = registry @source = source @location = location end |
Instance Attribute Details
#location ⇒ Parsing::Location (readonly)
13 14 15 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 13 def location @location end |
#registry ⇒ Store::Registry (readonly)
7 8 9 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 7 def registry @registry end |
#source ⇒ String (readonly)
10 11 12 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 10 def source @source end |
Instance Method Details
#index_word ⇒ String?
43 44 45 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 43 def index_word nearest_send_node&.selector_name end |
#method_candidates ⇒ Array<Store::Objects::MethodObject>
59 60 61 62 63 64 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 59 def method_candidates return [] unless valid? receiver_values .map { |value| Store::Query::FindSignature.new(registry).select(value, /\A#{Regexp.escape(index_word)}/) } .flatten end |
#nearest_send_node ⇒ Parsing::NodeObjects::SendNode?
29 30 31 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 29 def nearest_send_node @nearest_send_node ||= send_nodes_to_current_location.reverse.find { |node| node.on_parameter?(location) } end |
#receiver_type ⇒ Model::Types::Base
48 49 50 51 52 53 54 55 56 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 48 def receiver_type @receiver_type ||= begin if nearest_send_node evaluator.calculate_type(nearest_send_node.receiver_node) else Model::Types::InstanceType.new(analyzer.namespace_object.path) end end end |
#send_nodes_to_current_location ⇒ Array<Parsing::NodeObjects::SendNode>
34 35 36 37 38 39 40 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 34 def send_nodes_to_current_location @send_nodes_to_current_location ||= begin analyzer.nodes_to_current_location_from_root.map do |node| node.type == :send ? Parsing::NodeObjects::SendNode.new(node) : nil end.compact end end |
#valid? ⇒ Boolean
24 25 26 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 24 def valid? !!nearest_send_node end |