Class: RBI::Node
- Inherits:
-
Object
- Object
- RBI::Node
- Extended by:
- T::Helpers
- Defined in:
- lib/rbi/model.rb,
lib/rbi/printer.rb,
lib/rbi/rbs_printer.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/filter_versions.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#loc ⇒ Object
: Loc?.
-
#parent_tree ⇒ Object
: Tree?.
Instance Method Summary collapse
-
#compatible_with?(_other) ⇒ Boolean
Can ‘self` and `_other` be merged into a single definition? : (Node _other) -> bool.
-
#detach ⇒ Object
: -> void.
-
#initialize(loc: nil) ⇒ Node
constructor
: (?loc: Loc?) -> void.
-
#merge_with(other) ⇒ Object
Merge ‘self` and `other` into a single definition : (Node other) -> void.
-
#parent_conflict_tree ⇒ Object
: -> ConflictTree?.
-
#parent_scope ⇒ Object
: -> Scope?.
-
#print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) ⇒ Object
: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void.
-
#rbs_print(out: $stdout, indent: 0, print_locs: false, positional_names: true) ⇒ Object
: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> void.
-
#rbs_string(indent: 0, print_locs: false, positional_names: true) ⇒ Object
: (?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> String.
-
#replace(node) ⇒ Object
: (Node node) -> void.
-
#satisfies_version?(version) ⇒ Boolean
: (Gem::Version version) -> bool.
-
#string(indent: 0, print_locs: false, max_line_length: nil) ⇒ Object
: (?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> String.
Constructor Details
#initialize(loc: nil) ⇒ Node
: (?loc: Loc?) -> void
19 20 21 22 |
# File 'lib/rbi/model.rb', line 19 def initialize(loc: nil) @parent_tree = nil @loc = loc end |
Instance Attribute Details
#loc ⇒ Object
: Loc?
16 17 18 |
# File 'lib/rbi/model.rb', line 16 def loc @loc end |
#parent_tree ⇒ Object
: Tree?
13 14 15 |
# File 'lib/rbi/model.rb', line 13 def parent_tree @parent_tree end |
Instance Method Details
#compatible_with?(_other) ⇒ Boolean
Can ‘self` and `_other` be merged into a single definition? : (Node _other) -> bool
280 281 282 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 280 def compatible_with?(_other) true end |
#detach ⇒ Object
: -> void
25 26 27 28 29 30 31 |
# File 'lib/rbi/model.rb', line 25 def detach tree = parent_tree return unless tree tree.nodes.delete(self) self.parent_tree = nil end |
#merge_with(other) ⇒ Object
Merge ‘self` and `other` into a single definition : (Node other) -> void
286 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 286 def merge_with(other); end |
#parent_conflict_tree ⇒ Object
: -> ConflictTree?
289 290 291 292 293 294 295 296 297 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 289 def parent_conflict_tree parent = parent_tree #: Node? while parent return parent if parent.is_a?(ConflictTree) parent = parent.parent_tree end nil end |
#parent_scope ⇒ Object
: -> Scope?
47 48 49 50 51 |
# File 'lib/rbi/model.rb', line 47 def parent_scope parent = parent_tree #: Tree? parent = parent.parent_tree until parent.is_a?(Scope) || parent.nil? parent end |
#print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) ⇒ Object
: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void
828 829 830 831 |
# File 'lib/rbi/printer.rb', line 828 def print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) p = Printer.new(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length) p.visit(self) end |
#rbs_print(out: $stdout, indent: 0, print_locs: false, positional_names: true) ⇒ Object
: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> void
1127 1128 1129 1130 |
# File 'lib/rbi/rbs_printer.rb', line 1127 def rbs_print(out: $stdout, indent: 0, print_locs: false, positional_names: true) p = RBSPrinter.new(out: out, indent: indent, print_locs: print_locs, positional_names: positional_names) p.visit(self) end |
#rbs_string(indent: 0, print_locs: false, positional_names: true) ⇒ Object
: (?indent: Integer, ?print_locs: bool, ?positional_names: bool) -> String
1133 1134 1135 1136 1137 |
# File 'lib/rbi/rbs_printer.rb', line 1133 def rbs_string(indent: 0, print_locs: false, positional_names: true) out = StringIO.new rbs_print(out: out, indent: indent, print_locs: print_locs, positional_names: positional_names) out.string end |
#replace(node) ⇒ Object
: (Node node) -> void
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rbi/model.rb', line 34 def replace(node) tree = parent_tree raise ReplaceNodeError, "Can't replace #{self} without a parent tree" unless tree index = tree.nodes.index(self) raise ReplaceNodeError, "Can't find #{self} in #{tree} child nodes" unless index tree.nodes[index] = node node.parent_tree = tree self.parent_tree = nil end |
#satisfies_version?(version) ⇒ Boolean
: (Gem::Version version) -> bool
91 92 93 94 95 96 |
# File 'lib/rbi/rewriters/filter_versions.rb', line 91 def satisfies_version?(version) return true unless is_a?(NodeWithComments) requirements = version_requirements requirements.empty? || requirements.any? { |req| req.satisfied_by?(version) } end |
#string(indent: 0, print_locs: false, max_line_length: nil) ⇒ Object
: (?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> String
834 835 836 837 838 |
# File 'lib/rbi/printer.rb', line 834 def string(indent: 0, print_locs: false, max_line_length: nil) out = StringIO.new print(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length) out.string end |