class RBS::TypeAliasDependency
TypeAliasDependency calculates the dependencies between type aliases
The dependencies are normalized automatically.
Attributes
Hash[TypeName, Hash[TypeName, bool]]
A hash which stores the transitive closure of the directed graph
A hash table from type alias name to a hash name with keys of transitive dependencies
The source type name and dependencies are normalized.
Direct dependencies corresponds to a directed graph with vertices as types and directions based on assignment of types
A hash table from type alias name to itβs direct dependencies
The source type name and dependencies are normalized.
Public Class Methods
(env: Environment) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/type_alias_dependency.rb, line 14 def initialize(env:) @env = env end
Public Instance Methods
() → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/type_alias_dependency.rb, line 27 def build_dependencies return if @direct_dependencies # Initialize hash(a directed graph) @direct_dependencies = {} # Initialize dependencies as an empty hash @dependencies = {} # Iterate over alias declarations inserted into environment env.type_alias_decls.each do |name, entry| # Construct a directed graph by recursively extracting type aliases @direct_dependencies[name] = direct_dependency(entry.decl.type) # Initialize dependencies with an empty hash @dependencies[name] = {} end end
(TypeName alias_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/type_alias_dependency.rb, line 19 def circular_definition?(alias_name) # Construct transitive closure, if not constructed already transitive_closure() unless @dependencies alias_name = env.normalize_type_name!(alias_name) @dependencies[alias_name][alias_name] end
Check if an alias type definition is circular & prohibited
Returns true if given type alias is circular
Normalized given type name automatically.
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/type_alias_dependency.rb, line 57 def dependencies_of(name) name = env.normalize_type_name!(name) @dependencies[name].each_key.to_set end
Returns the set of dependencies from the given type name
Given type name will be normalized automatically. Returns normalized type names.
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/type_alias_dependency.rb, line 52 def direct_dependencies_of(name) name = env.normalize_type_name!(name) @direct_dependencies[name] end
Returns the set of direct dependencies from the given type name
Given type name will be normalized automatically. Returns normalized type names.
() → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/type_alias_dependency.rb, line 43 def transitive_closure # Construct a graph of direct dependencies build_dependencies() # Construct transitive closure by using DFS(recursive technique) @direct_dependencies.each_key do |name| dependency(name, name) end end