class DeepCover::Node::If

Public Instance Methods

branches() click to toggle source
# File lib/deep_cover/node/if.rb, line 32
def branches
  [true_branch, false_branch]
end
branches_summary(of_branches) click to toggle source
# File lib/deep_cover/node/if.rb, line 36
def branches_summary(of_branches)
  of_branches.map do |jump|
    "#{'implicit ' if jump.is_a?(EmptyBody) && !has_else?}#{jump == false_branch ? 'falsy' : 'truthy'} branch"
  end.join(' and ')
end
child_can_be_empty(child, name) click to toggle source
# File lib/deep_cover/node/if.rb, line 21
def child_can_be_empty(child, name)
  raise 'Unexpected empty body' if name == :condition || style == :ternary
  if (name == :true_branch) == [:if, :elsif].include?(style)
    (base_node.loc.begin || base_node.children[0].loc.expression.succ).end
  elsif has_else?
    base_node.loc.else.end.succ
  else
    true # implicit else
  end
end
deepest_elsif_node() click to toggle source
# File lib/deep_cover/node/if.rb, line 60
def deepest_elsif_node
  raise 'Not an elsif' if style != :elsif
  return self if loc_hash[:else] && loc_hash[:else].source == 'else'
  return self if false_branch.is_a?(EmptyBody)
  false_branch.deepest_elsif_node
end
execution_count() click to toggle source
# File lib/deep_cover/node/if.rb, line 42
def execution_count
  condition.flow_completion_count
end
has_else?() click to toggle source
# File lib/deep_cover/node/if.rb, line 67
def has_else?
  !!base_node.loc.to_hash[:else]
end
modifier?() click to toggle source
# File lib/deep_cover/node/if.rb, line 71
def modifier?
  loc_hash[:keyword] && root_if_node.loc_hash[:end].nil?
end
root_if_node() click to toggle source
# File lib/deep_cover/node/if.rb, line 52
def root_if_node
  if style != :elsif
    self
  else
    parent.root_if_node
  end
end
style() click to toggle source

returns on of %i[ternary if unless elsif]

# File lib/deep_cover/node/if.rb, line 47
def style
  keyword = loc_hash[:keyword]
  keyword ? keyword.source.to_sym : :ternary
end