class Yoda::Evaluation::SignatureDiscovery

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.

Attributes

location[R]

@return [Parsing::Location]

registry[R]

@return [Store::Registry]

source[R]

@return [String]

Public Class Methods

new(registry, source, location) click to toggle source

@param registry [Store::Registry] @param source [String] @param location [Parsing::Location]

# File lib/yoda/evaluation/signature_discovery.rb, line 18
def initialize(registry, source, location)
  @registry = registry
  @source = source
  @location = location
end

Public Instance Methods

index_word() click to toggle source

@return [String, nil]

# File lib/yoda/evaluation/signature_discovery.rb, line 43
def index_word
  nearest_send_node&.selector_name
end
method_candidates() click to toggle source

@return [Array<Store::Objects::MethodObject>]

# 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() click to toggle source

@return [Parsing::NodeObjects::SendNode, nil]

# 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() click to toggle source

@return [Model::Types::Base]

# 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() click to toggle source

@return [Array<Parsing::NodeObjects::SendNode>]

# 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?() click to toggle source
# File lib/yoda/evaluation/signature_discovery.rb, line 24
def valid?
  !!nearest_send_node
end

Private Instance Methods

analyzer() click to toggle source

@return [SourceAnalyzer]

# File lib/yoda/evaluation/signature_discovery.rb, line 75
def analyzer
  @analyzer ||= Parsing::SourceAnalyzer.from_source(source, location)
end
evaluator() click to toggle source

@return [Evaluator]

# File lib/yoda/evaluation/signature_discovery.rb, line 80
def evaluator
  @evaluator ||= Evaluator.from_ast(registry, analyzer.ast, location)
end
receiver_values() click to toggle source

@return [Array<Store::Values::Base>]

# File lib/yoda/evaluation/signature_discovery.rb, line 69
def receiver_values
  return [] unless valid?
  @receiver_values ||= evaluator.calculate_values(nearest_send_node.receiver_node)
end