Module: Hashira::Analysis::TypeWalk
- Defined in:
- lib/hashira/analysis/type_walk.rb
Class Method Summary collapse
- .descend(node, stack, roots) ⇒ Object
- .each(node, stack = [], roots: nil) {|node, full| ... } ⇒ Object
- .roots(trees) ⇒ Object
- .type?(node) ⇒ Boolean
Class Method Details
.descend(node, stack, roots) ⇒ Object
23 24 25 |
# File 'lib/hashira/analysis/type_walk.rb', line 23 def descend(node, stack, roots, &) (node ? node.compact_child_nodes : []).each { each(it, stack, roots:, &) } end |
.each(node, stack = [], roots: nil) {|node, full| ... } ⇒ Object
14 15 16 17 18 19 |
# File 'lib/hashira/analysis/type_walk.rb', line 14 def each(node, stack = [], roots: nil, &) return descend(node, stack, roots, &) unless type?(node) full = Syntax.anchor(stack, Syntax.segments(node.constant_path), roots) yield(node, full) descend(node.body, stack + [full], roots, &) end |
.roots(trees) ⇒ Object
10 11 12 |
# File 'lib/hashira/analysis/type_walk.rb', line 10 def roots(trees) trees.each_value.with_object(Set.new) { |tree, set| each(tree) { |_node, full| set << full } } end |
.type?(node) ⇒ Boolean
21 |
# File 'lib/hashira/analysis/type_walk.rb', line 21 def type?(node) = node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode) |