Class: AppMap::Inspect::ParseNode
- Inherits:
-
ParseNodeStruct
- Object
- Struct
- ParseNodeStruct
- AppMap::Inspect::ParseNode
- Extended by:
- Forwardable
- Defined in:
- lib/appmap/inspect/parse_node.rb
Overview
ParseNode wraps a generic AST parse node.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from ParseNodeStruct
Class Method Summary collapse
-
.from_node(node, file_path, ancestors) ⇒ Object
Build a ParseNode from an AST node.
Instance Method Summary collapse
-
#enclosing_type_node ⇒ Object
Gets the AST node of the module or class which encloses this node.
- #parent_node ⇒ Object
- #preceding_sibling_nodes ⇒ Object
- #public? ⇒ Boolean
Class Method Details
.from_node(node, file_path, ancestors) ⇒ Object
Build a ParseNode from an AST node.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/appmap/inspect/parse_node.rb', line 18 def from_node(node, file_path, ancestors) case node.type when :class, :module ClassParseNode.new(node, file_path, ancestors.dup) when :def InstanceMethodParseNode.new(node, file_path, ancestors.dup) when :defs StaticMethodParseNode.new(node, file_path, ancestors.dup) \ if StaticMethodParseNode.static?(node) end end |
Instance Method Details
#enclosing_type_node ⇒ Object
Gets the AST node of the module or class which encloses this node.
40 41 42 43 44 |
# File 'lib/appmap/inspect/parse_node.rb', line 40 def enclosing_type_node ancestors.reverse.find do |a| i[class module].include?(a.type) end end |
#parent_node ⇒ Object
46 47 48 |
# File 'lib/appmap/inspect/parse_node.rb', line 46 def parent_node ancestors[-1] end |
#preceding_sibling_nodes ⇒ Object
50 51 52 53 54 |
# File 'lib/appmap/inspect/parse_node.rb', line 50 def preceding_sibling_nodes return [] unless parent_node index_of_this_node = parent_node.children.index { |c| c == node } parent_node.children[0...index_of_this_node] end |
#public? ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/appmap/inspect/parse_node.rb', line 31 def public? preceding_send = preceding_sibling_nodes .reverse .select { |n| n.respond_to?(:type) && n.type == :send } .find { |n| i[public protected private].member?(n.children[1]) } preceding_send.nil? || preceding_send.children[1] == :public end |