Class: RBS::Resolver::TypeNameResolver
- Inherits:
-
Object
- Object
- RBS::Resolver::TypeNameResolver
- Defined in:
- lib/rbs/resolver/type_name_resolver.rb
Instance Attribute Summary collapse
-
#all_names ⇒ Object
readonly
Returns the value of attribute all_names.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
- #has_name?(full_name) ⇒ Boolean
-
#initialize(env) ⇒ TypeNameResolver
constructor
A new instance of TypeNameResolver.
- #resolve(type_name, context:) ⇒ Object
- #resolve_in(type_name, context) ⇒ Object
- #try_cache(query) ⇒ Object
Constructor Details
#initialize(env) ⇒ TypeNameResolver
Returns a new instance of TypeNameResolver.
7 8 9 10 11 12 13 14 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 7 def initialize(env) @all_names = Set[] @cache = {} all_names.merge(env.class_decls.keys) all_names.merge(env.interface_decls.keys) all_names.merge(env.alias_decls.keys) end |
Instance Attribute Details
#all_names ⇒ Object (readonly)
Returns the value of attribute all_names.
4 5 6 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 4 def all_names @all_names end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5 6 7 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 5 def cache @cache end |
Instance Method Details
#has_name?(full_name) ⇒ Boolean
48 49 50 51 52 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 48 def has_name?(full_name) if all_names.include?(full_name) full_name end end |
#resolve(type_name, context:) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 23 def resolve(type_name, context:) if type_name.absolute? return type_name end try_cache([type_name, context]) do resolve_in(type_name, context) end end |
#resolve_in(type_name, context) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 33 def resolve_in(type_name, context) if context parent, child = context case child when false resolve_in(type_name, parent) when TypeName name = type_name.with_prefix(child.to_namespace) has_name?(name) || resolve_in(type_name, parent) end else has_name?(type_name.absolute!) end end |
#try_cache(query) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/rbs/resolver/type_name_resolver.rb', line 16 def try_cache(query) cache.fetch(query) do result = yield cache[query] = result end end |