class RBS::Resolver::TypeNameResolver

Attributes

all_names[R]
cache[R]

Public Class Methods

new(env) click to toggle source
# File rbs-2.7.0/lib/rbs/resolver/type_name_resolver.rb, line 9
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

Public Instance Methods

has_name?(full_name) click to toggle source
# File rbs-2.7.0/lib/rbs/resolver/type_name_resolver.rb, line 50
def has_name?(full_name)
  if all_names.include?(full_name)
    full_name
  end
end
resolve(type_name, context:) click to toggle source
# File rbs-2.7.0/lib/rbs/resolver/type_name_resolver.rb, line 25
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) click to toggle source
# File rbs-2.7.0/lib/rbs/resolver/type_name_resolver.rb, line 35
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) { || ... } click to toggle source
# File rbs-2.7.0/lib/rbs/resolver/type_name_resolver.rb, line 18
def try_cache(query)
  cache.fetch(query) do
    result = yield
    cache[query] = result
  end
end