class RBS::Environment::UseMap
Attributes
use_dirs[R]
Public Class Methods
new(table:)
click to toggle source
# File rbs-3.2.2/lib/rbs/environment/use_map.rb, line 30 def initialize(table:) @use_dirs = [] @map = {} @table = table end
Public Instance Methods
build_map(clause)
click to toggle source
# File rbs-3.2.2/lib/rbs/environment/use_map.rb, line 36 def build_map(clause) case clause when AST::Directives::Use::SingleClause if clause.new_name @map[clause.new_name] = clause.type_name.absolute! else @map[clause.type_name.name] = clause.type_name.absolute! end when AST::Directives::Use::WildcardClause @table.children.fetch(clause.namespace.absolute!).each do |child| @map[child.name] = child end end self end
resolve(type_name)
click to toggle source
# File rbs-3.2.2/lib/rbs/environment/use_map.rb, line 72 def resolve(type_name) resolve?(type_name) || type_name end
resolve?(type_name)
click to toggle source
# File rbs-3.2.2/lib/rbs/environment/use_map.rb, line 53 def resolve?(type_name) return if type_name.absolute? hd, *tl = type_name.namespace.path if hd # namespace is not empty if tn = @map[hd] path = [*tn.namespace.path, tn.name, *tl] TypeName.new( namespace: Namespace.new(absolute: true, path: path), name: type_name.name ) end else @map[type_name.name] end end