Class: Yoda::Evaluation::SignatureDiscovery
- Inherits:
-
Object
- Object
- Yoda::Evaluation::SignatureDiscovery
- Defined in:
- lib/yoda/evaluation/signature_discovery.rb
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.
16 17 18 19 20 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 16 def initialize(registry, source, location) @registry = registry @source = source @location = location end |
Instance Attribute Details
#location ⇒ Parsing::Location (readonly)
11 12 13 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 11 def location @location end |
#registry ⇒ Store::Registry (readonly)
5 6 7 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 5 def registry @registry end |
#source ⇒ String (readonly)
8 9 10 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 8 def source @source end |
Instance Method Details
#index_word ⇒ String?
41 42 43 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 41 def index_word nearest_send_node&.selector_name end |
#method_candidates ⇒ Array<Store::Objects::MethodObject>
57 58 59 60 61 62 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 57 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?
27 28 29 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 27 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
46 47 48 49 50 51 52 53 54 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 46 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>
32 33 34 35 36 37 38 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 32 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
22 23 24 |
# File 'lib/yoda/evaluation/signature_discovery.rb', line 22 def valid? !!nearest_send_node end |