Class: RBI::Node

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/rbi/model.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/group_nodes.rb,
lib/rbi/rewriters/merge_trees.rb

Direct Known Subclasses

Comment, NodeWithComments, Sig, SigParam, Visibility

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loc: nil) ⇒ Node



18
19
20
21
# File 'lib/rbi/model.rb', line 18

def initialize(loc: nil)
  @parent_tree = nil
  @loc = loc
end

Instance Attribute Details

#locObject

Returns the value of attribute loc.



15
16
17
# File 'lib/rbi/model.rb', line 15

def loc
  @loc
end

#parent_treeObject

Returns the value of attribute parent_tree.



12
13
14
# File 'lib/rbi/model.rb', line 12

def parent_tree
  @parent_tree
end

Instance Method Details

#accept_printer(v) ⇒ Object



124
# File 'lib/rbi/printer.rb', line 124

def accept_printer(v); end

#compatible_with?(_other) ⇒ Boolean



252
253
254
# File 'lib/rbi/rewriters/merge_trees.rb', line 252

def compatible_with?(_other)
  true
end

#detachObject



24
25
26
27
28
29
# File 'lib/rbi/model.rb', line 24

def detach
  tree = parent_tree
  return unless tree
  tree.nodes.delete(self)
  self.parent_tree = nil
end

#group_kindObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rbi/rewriters/group_nodes.rb', line 48

def group_kind
  case self
  when Include, Extend
    Group::Kind::Mixins
  when Helper
    Group::Kind::Helpers
  when TypeMember
    Group::Kind::TypeMembers
  when MixesInClassMethods
    Group::Kind::MixesInClassMethods
  when TStructField
    Group::Kind::TStructFields
  when TEnumBlock
    Group::Kind::TEnums
  when VisibilityGroup
    Group::Kind::Methods
  when Method
    if name == "initialize"
      Group::Kind::Inits
    else
      Group::Kind::Methods
    end
  when Scope, Const
    Group::Kind::Consts
  else
    raise "Unknown group for #{self}"
  end
end

#merge_with(other) ⇒ Object



258
# File 'lib/rbi/rewriters/merge_trees.rb', line 258

def merge_with(other); end

#oneline?Boolean



140
141
142
# File 'lib/rbi/printer.rb', line 140

def oneline?
  true
end

#parent_conflict_treeObject



261
262
263
264
265
266
267
268
# File 'lib/rbi/rewriters/merge_trees.rb', line 261

def parent_conflict_tree
  parent = T.let(parent_tree, T.nilable(Node))
  while parent
    return parent if parent.is_a?(ConflictTree)
    parent = parent.parent_tree
  end
  nil
end

#parent_scopeObject



43
44
45
46
47
# File 'lib/rbi/model.rb', line 43

def parent_scope
  parent = T.let(parent_tree, T.nilable(Tree))
  parent = parent.parent_tree until parent.is_a?(Scope) || parent.nil?
  parent
end


127
128
129
130
# File 'lib/rbi/printer.rb', line 127

def print(out: $stdout, indent: 0, print_locs: false)
  p = Printer.new(out: out, indent: indent, print_locs: print_locs)
  p.visit(self)
end

#replace(node) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/rbi/model.rb', line 32

def replace(node)
  tree = parent_tree
  raise unless tree
  index = tree.nodes.index(self)
  raise unless index
  tree.nodes[index] = node
  node.parent_tree = tree
  self.parent_tree = nil
end

#string(indent: 0, print_locs: false) ⇒ Object



133
134
135
136
137
# File 'lib/rbi/printer.rb', line 133

def string(indent: 0, print_locs: false)
  out = StringIO.new
  print(out: out, indent: indent, print_locs: print_locs)
  out.string
end