Class: DeepCover::Node::SendBase

Inherits:
DeepCover::Node show all
Defined in:
lib/deep_cover/node/send.rb

Direct Known Subclasses

CsendInnerSend, Send, SendWithBlock

Constant Summary

Constants inherited from DeepCover::Node

CLASSES, Complex, Cvasgn, Dsym, Erange, Float, Int, Ivar, Kwarg, Kwoptarg, Kwrestarg, OrAsgn, Rational, Sym, True, Zsuper

Instance Attribute Summary

Attributes inherited from DeepCover::Node

#base_node, #children, #index, #next_sibling, #parent, #previous_sibling

Instance Method Summary collapse

Methods inherited from DeepCover::Node

[], #[], atom, #children_nodes, #covered_code, define_module_class, #each_node, #fancy_type, #find_all, has_evaluated_segments, inherited, #initialize, #simple_literal?, #to_s, #type

Methods included from Memoize

#freeze, included

Constructor Details

This class inherits a constructor from DeepCover::Node

Instance Method Details

#loc_hashObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/deep_cover/node/send.rb', line 14

def loc_hash
  hash = super.dup
  selector = hash.delete(:selector)

  # Special case for foo[bar]=baz, but not for foo.[]= bar, baz: we split selector into begin and end
  if base_node.location.dot == nil && [:[], :[]=].include?(message)
    hash[:selector_begin] = selector.resize(1)
    hash[:selector_end] = Parser::Source::Range.new(selector.source_buffer, selector.end_pos - 1, selector.end_pos)
  else
    hash.delete(:dot) if type == :safe_send # Hack. API to get a Parser::AST::Send::Map without the dot is crappy.
    hash[:selector_begin] = selector
  end

  hash
end

#rewriting_rulesObject

Rules must be ordered inner-most first



31
32
33
34
35
36
37
38
# File 'lib/deep_cover/node/send.rb', line 31

def rewriting_rules
  rules = super
  if need_parentheses?
    range = arguments.last.expression.with(begin_pos: loc_hash[:selector_begin].end_pos)
    rules.unshift [range, '(%{node})']
  end
  rules
end