Class: SimpleCov::StaticCoverageExtractor::Visitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- SimpleCov::StaticCoverageExtractor::Visitor
- Includes:
- LocationConventions, MethodCollector
- Defined in:
- lib/simplecov/static_coverage_extractor/visitor.rb
Overview
Prism visitor that accumulates branch and method tuples in the
shape Ruby's Coverage reports. Tuple ids are sequential across
the file — Coverage uses sequential ids too, so this matches the
conventional shape. Only defined when Prism is loadable;
StaticCoverageExtractor.available? is the runtime gate.
Constant Summary
Constants included from LocationConventions
LocationConventions::LEGACY_COVERAGE_LOCATIONS
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
Instance Method Summary collapse
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
- #visit_call_node(node) ⇒ Object
- #visit_case_match_node(node) ⇒ Object
-
#visit_case_node(node) ⇒ Object
case/whenandcase/in(pattern matching) parse as CaseNode and CaseMatchNode respectively. -
#visit_if_node(node) ⇒ Object
if/unless/ postfix-if / postfix-unless / ternary all parse as IfNode (or UnlessNode). - #visit_unless_node(node) ⇒ Object
- #visit_until_node(node) ⇒ Object
-
#visit_while_node(node) ⇒ Object
while/untilloops get a single:bodyarm.
Methods included from MethodCollector
#visit_class_node, #visit_def_node, #visit_module_node
Constructor Details
#initialize ⇒ Visitor
Returns a new instance of Visitor.
39 40 41 42 43 44 45 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 39 def initialize super @branches = {} @methods = {} @next_id = 0 @class_stack = [] end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
37 38 39 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 37 def branches @branches end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
37 38 39 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 37 def methods @methods end |
Instance Method Details
#visit_call_node(node) ⇒ Object
63 64 65 66 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 63 def visit_call_node(node) (node) if node.respond_to?(:safe_navigation?) && node. super end |
#visit_case_match_node(node) ⇒ Object
76 77 78 79 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 76 def visit_case_match_node(node) emit_case_like(node, :in) super end |
#visit_case_node(node) ⇒ Object
case/when and case/in (pattern matching) parse as CaseNode
and CaseMatchNode respectively. When there's no explicit else,
Coverage synthesizes one at the case's range.
71 72 73 74 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 71 def visit_case_node(node) emit_case_like(node, :when) super end |
#visit_if_node(node) ⇒ Object
if / unless / postfix-if / postfix-unless / ternary all parse
as IfNode (or UnlessNode). Both carry a then arm (the
statements body) and an optional subsequent (an ElseNode for
else, another IfNode for elsif). When the subsequent is
missing, Coverage synthesizes a :else arm attributed to the
whole condition's range — we do the same.
53 54 55 56 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 53 def visit_if_node(node) emit_if_like(node, :if) super end |
#visit_unless_node(node) ⇒ Object
58 59 60 61 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 58 def visit_unless_node(node) emit_if_like(node, :unless) super end |
#visit_until_node(node) ⇒ Object
88 89 90 91 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 88 def visit_until_node(node) emit_loop(node, :until) super end |
#visit_while_node(node) ⇒ Object
while / until loops get a single :body arm. No synthetic
else (the loop either runs the body or doesn't).
83 84 85 86 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 83 def visit_while_node(node) emit_loop(node, :while) super end |