-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment_walker.rbs
65 lines (53 loc) · 1.79 KB
/
environment_walker.rbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module RBS
# EnvironmentWalker provides topological sort of class/module definitions.
#
# If a method, attribute, or ancestor in a class definition have a reference to another class, it is dependency.
#
# ```rb
# walker = EnvironmentWalker.new(env: env)
#
# walker.each_strongly_connected_component do |scc|
# # Yields an array of strongly connected components.
# end
# ```
#
# The `#only_ancestors!` method limits the dependency only to ancestors.
# Only super classes and included modules are dependencies with the option.
# This is useful to calculate the dependencies of class hierarchy.
#
# ```rb
# walker = EnvironmentWalker.new(env: env).only_ancestors!
#
# walker.each_strongly_connected_component do |scc|
# # Yields an array of strongly connected components.
# end
# ```
#
class EnvironmentWalker
class InstanceNode
attr_reader type_name: TypeName
def initialize: (type_name: TypeName) -> void
end
class SingletonNode
attr_reader type_name: TypeName
def initialize: (type_name: TypeName) -> void
end
class TypeNameNode
attr_reader type_name: TypeName
def initialize: (type_name: TypeName) -> void
end
attr_reader env: Environment
attr_reader only_ancestors: bool
attr_reader builder: DefinitionBuilder
def initialize: (env: Environment) -> void
def only_ancestors!: (?bool only) -> self
def only_ancestors?: () -> bool
type node = InstanceNode | SingletonNode | TypeNameNode
include TSort[node]
def tsort_each_node: () { (node) -> void } -> void
def tsort_each_child: (node) { (node) -> void } -> void
private
def each_type_name: (Types::t) { (TypeName) -> void } -> void
def each_type_node: (Types::t) { (node) -> void } -> void
end
end