Class: Mutant::AST::Structure::Node Private

Inherits:
Object
  • Object
show all
Includes:
Unparser::Adamantium
Defined in:
lib/mutant/ast/structure.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Fixed, Variable

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fixed(values) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
# File 'lib/mutant/ast/structure.rb', line 99

def self.fixed(values)
  values.each_with_index.map do |(klass, name), index|
    klass.new(index:, name:)
  end
end

Instance Method Details

#attribute(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



87
88
89
# File 'lib/mutant/ast/structure.rb', line 87

def attribute(name)
  maybe_attribute(name) or fail "Node #{type} does not have fixed attribute #{name}"
end

#attributesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/mutant/ast/structure.rb', line 79

def attributes
  fixed.select(&:attribute?).to_h { |child| [child.name, child] }
end

#descendant(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



83
84
85
# File 'lib/mutant/ast/structure.rb', line 83

def descendant(name)
  maybe_descendant(name) or fail "Node #{type} does not have fixed descendant #{name}"
end

#descendantsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
# File 'lib/mutant/ast/structure.rb', line 75

def descendants
  fixed.select(&:descendant?).to_h { |child| [child.name, child] }
end

#each_descendant(node, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mutant/ast/structure.rb', line 61

def each_descendant(node, &block)
  descendants.each_value do |descendant|
    value = descendant.value(node)

    block.call(value) if value
  end

  variable_descendants(node).each do |value|
    block.call(value) if value
  end

  self
end

#each_descendant_deep(node, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
# File 'lib/mutant/ast/structure.rb', line 49

def each_descendant_deep(node, &block)
  each_descendant(node) do |descendant|
    block.call(descendant)
    Structure.for(descendant.type).each_descendant_deep(descendant, &block)
  end
end

#each_node(node, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
# File 'lib/mutant/ast/structure.rb', line 56

def each_node(node, &block)
  block.call(node)
  each_descendant_deep(node, &block)
end

#maybe_attribute(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



91
92
93
# File 'lib/mutant/ast/structure.rb', line 91

def maybe_attribute(name)
  attributes[name]
end

#maybe_descendant(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



95
96
97
# File 'lib/mutant/ast/structure.rb', line 95

def maybe_descendant(name)
  descendants[name]
end