Class: RBS::Environment::UseMap
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/rbs/environment/use_map.rb |
Class Method Summary
- .new(table:) ⇒ UseMap constructor
Instance Attribute Summary
- #use_dirs readonly
Instance Method Summary
Constructor Details
.new(table:) ⇒ UseMap
# File 'lib/rbs/environment/use_map.rb', line 30
def initialize(table:) @use_dirs = [] @map = {} @table = table end
Instance Attribute Details
#use_dirs (readonly)
[ GitHub ]# File 'lib/rbs/environment/use_map.rb', line 28
attr_reader :use_dirs
Instance Method Details
#build_map(clause)
[ GitHub ]# File '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)
[ GitHub ]# File 'lib/rbs/environment/use_map.rb', line 72
def resolve(type_name) resolve?(type_name) || type_name end
#resolve?(type_name) ⇒ Boolean
# File '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