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

Arg, Comment, NodeWithComments, Sig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loc: nil) ⇒ Node

Returns a new instance of 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

Returns:

  • (Boolean)


283
284
285
# File 'lib/rbi/rewriters/merge_trees.rb', line 283

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
76
77
78
79
# 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 Send
    Group::Kind::Sends
  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 SingletonClass
    Group::Kind::SingletonClasses
  when Scope, Const
    Group::Kind::Consts
  else
    raise "Unknown group for #{self}"
  end
end

#merge_with(other) ⇒ Object



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

def merge_with(other); end

#oneline?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/rbi/printer.rb', line 149

def oneline?
  true
end

#parent_conflict_treeObject



292
293
294
295
296
297
298
299
# File 'lib/rbi/rewriters/merge_trees.rb', line 292

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


140
141
142
143
144
145
146
# File 'lib/rbi/printer.rb', line 140

def print_blank_line_before(v)
  previous_node = v.previous_node
  return unless previous_node
  return if previous_node.is_a?(BlankLine)
  return if previous_node.oneline? && oneline?
  v.printn
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