Class: RBS::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/environment.rb,
lib/rbs/environment/use_map.rb

Defined Under Namespace

Modules: ContextUtil Classes: ClassAliasEntry, ClassEntry, ConstantEntry, GlobalEntry, InterfaceEntry, ModuleAliasEntry, ModuleEntry, MultiEntry, SingleEntry, TypeAliasEntry, UseMap

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rbs/environment.rb', line 145

def initialize
  @signatures = {}
  @declarations = []

  @class_decls = {}
  @interface_decls = {}
  @type_alias_decls = {}
  @constant_decls = {}
  @global_decls = {}
  @class_alias_decls = {}
  @normalize_module_name_cache = {}
end

Instance Attribute Details

#class_alias_declsObject (readonly)

Returns the value of attribute class_alias_decls.



12
13
14
# File 'lib/rbs/environment.rb', line 12

def class_alias_decls
  @class_alias_decls
end

#class_declsObject (readonly)

Returns the value of attribute class_decls.



7
8
9
# File 'lib/rbs/environment.rb', line 7

def class_decls
  @class_decls
end

#constant_declsObject (readonly)

Returns the value of attribute constant_decls.



10
11
12
# File 'lib/rbs/environment.rb', line 10

def constant_decls
  @constant_decls
end

#declarationsObject (readonly)

Returns the value of attribute declarations.



5
6
7
# File 'lib/rbs/environment.rb', line 5

def declarations
  @declarations
end

#global_declsObject (readonly)

Returns the value of attribute global_decls.



11
12
13
# File 'lib/rbs/environment.rb', line 11

def global_decls
  @global_decls
end

#interface_declsObject (readonly)

Returns the value of attribute interface_decls.



8
9
10
# File 'lib/rbs/environment.rb', line 8

def interface_decls
  @interface_decls
end

#signaturesObject (readonly)

Returns the value of attribute signatures.



14
15
16
# File 'lib/rbs/environment.rb', line 14

def signatures
  @signatures
end

#type_alias_declsObject (readonly)

Returns the value of attribute type_alias_decls.



9
10
11
# File 'lib/rbs/environment.rb', line 9

def type_alias_decls
  @type_alias_decls
end

Class Method Details

.from_loader(loader) ⇒ Object



170
171
172
173
174
# File 'lib/rbs/environment.rb', line 170

def self.from_loader(loader)
  self.new.tap do |env|
    loader.load(env: env)
  end
end

Instance Method Details

#<<(decl) ⇒ Object



470
471
472
473
474
# File 'lib/rbs/environment.rb', line 470

def <<(decl)
  declarations << decl
  insert_decl(decl, outer: [], namespace: Namespace.root)
  self
end

#absolute_type(resolver, map, type, context:) ⇒ Object



792
793
794
795
796
# File 'lib/rbs/environment.rb', line 792

def absolute_type(resolver, map, type, context:)
  type.map_type_name do |name, _, _|
    absolute_type_name(resolver, map, name, context: context)
  end
end

#absolute_type_name(resolver, map, type_name, context:) ⇒ Object



787
788
789
790
# File 'lib/rbs/environment.rb', line 787

def absolute_type_name(resolver, map, type_name, context:)
  type_name = map.resolve(type_name)
  resolver.resolve(type_name, context: context) || type_name
end

#add_signature(buffer:, directives:, decls:) ⇒ Object



476
477
478
479
480
481
# File 'lib/rbs/environment.rb', line 476

def add_signature(buffer:, directives:, decls:)
  signatures[buffer] = [directives, decls]
  decls.each do |decl|
    self << decl
  end
end

#append_context(context, decl) ⇒ Object



528
529
530
531
532
533
534
535
# File 'lib/rbs/environment.rb', line 528

def append_context(context, decl)
  if (_, last = context)
    last or raise
    [context, last + decl.name]
  else
    [nil, decl.name.absolute!]
  end
end

#buffersObject



803
804
805
# File 'lib/rbs/environment.rb', line 803

def buffers
  signatures.keys
end

#class_alias?(name) ⇒ Boolean

Returns:

  • (Boolean)


218
219
220
221
222
223
224
# File 'lib/rbs/environment.rb', line 218

def class_alias?(name)
  if decl = class_alias_decls[name]
    decl.decl.is_a?(AST::Declarations::ClassAlias)
  else
    false
  end
end

#class_decl?(name) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/rbs/environment.rb', line 202

def class_decl?(name)
  class_decls[name].is_a?(ClassEntry)
end

#class_entry(type_name) ⇒ Object



226
227
228
229
230
231
232
233
# File 'lib/rbs/environment.rb', line 226

def class_entry(type_name)
  case
  when (class_entry = class_decls[type_name]).is_a?(ClassEntry)
    class_entry
  when (class_alias = class_alias_decls[type_name]).is_a?(ClassAliasEntry)
    class_alias
  end
end

#constant_decl?(name) ⇒ Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/rbs/environment.rb', line 198

def constant_decl?(name)
  constant_decls.key?(name)
end

#constant_entry(type_name) ⇒ Object



274
275
276
# File 'lib/rbs/environment.rb', line 274

def constant_entry(type_name)
  class_entry(type_name) || module_entry(type_name) || constant_decls[type_name]
end

#constant_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/rbs/environment.rb', line 194

def constant_name?(name)
  constant_decl?(name) || module_name?(name)
end

#initialize_copy(other) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rbs/environment.rb', line 158

def initialize_copy(other)
  @signatures = other.signatures.dup
  @declarations = other.declarations.dup

  @class_decls = other.class_decls.dup
  @interface_decls = other.interface_decls.dup
  @type_alias_decls = other.type_alias_decls.dup
  @constant_decls = other.constant_decls.dup
  @global_decls = other.global_decls.dup
  @class_alias_decls = other.class_alias_decls.dup
end

#insert_decl(decl, outer:, namespace:) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/rbs/environment.rb', line 373

def insert_decl(decl, outer:, namespace:)
  case decl
  when AST::Declarations::Class, AST::Declarations::Module
    name = decl.name.with_prefix(namespace)

    if cdecl = constant_entry(name)
      if cdecl.is_a?(ConstantEntry) || cdecl.is_a?(ModuleAliasEntry) || cdecl.is_a?(ClassAliasEntry)
        raise DuplicatedDeclarationError.new(name, decl, cdecl.decl)
      end
    end

    unless class_decls.key?(name)
      case decl
      when AST::Declarations::Class
        class_decls[name] ||= ClassEntry.new(name: name)
      when AST::Declarations::Module
        class_decls[name] ||= ModuleEntry.new(name: name)
      end
    end

    existing_entry = class_decls[name]

    case
    when decl.is_a?(AST::Declarations::Module) && existing_entry.is_a?(ModuleEntry)
      existing_entry.insert(decl: decl, outer: outer)
    when decl.is_a?(AST::Declarations::Class) && existing_entry.is_a?(ClassEntry)
      existing_entry.insert(decl: decl, outer: outer)
    else
      raise DuplicatedDeclarationError.new(name, decl, existing_entry.decls[0].decl)
    end

    prefix = outer + [decl]
    ns = name.to_namespace
    decl.each_decl do |d|
      insert_decl(d, outer: prefix, namespace: ns)
    end

  when AST::Declarations::Interface
    name = decl.name.with_prefix(namespace)

    if interface_entry = interface_decls[name]
      raise DuplicatedDeclarationError.new(name, decl, interface_entry.decl)
    end

    interface_decls[name] = InterfaceEntry.new(name: name, decl: decl, outer: outer)

  when AST::Declarations::TypeAlias
    name = decl.name.with_prefix(namespace)

    if entry = type_alias_decls[name]
      raise DuplicatedDeclarationError.new(name, decl, entry.decl)
    end

    type_alias_decls[name] = TypeAliasEntry.new(name: name, decl: decl, outer: outer)

  when AST::Declarations::Constant
    name = decl.name.with_prefix(namespace)

    if entry = constant_entry(name)
      case entry
      when ClassAliasEntry, ModuleAliasEntry, ConstantEntry
        raise DuplicatedDeclarationError.new(name, decl, entry.decl)
      when ClassEntry, ModuleEntry
        raise DuplicatedDeclarationError.new(name, decl, *entry.decls.map(&:decl))
      end
    end

    constant_decls[name] = ConstantEntry.new(name: name, decl: decl, outer: outer)

  when AST::Declarations::Global
    if entry = global_decls[decl.name]
      raise DuplicatedDeclarationError.new(decl.name, decl, entry.decl)
    end

    global_decls[decl.name] = GlobalEntry.new(name: decl.name, decl: decl, outer: outer)

  when AST::Declarations::ClassAlias, AST::Declarations::ModuleAlias
    name = decl.new_name.with_prefix(namespace)

    if entry = constant_entry(name)
      case entry
      when ClassAliasEntry, ModuleAliasEntry, ConstantEntry
        raise DuplicatedDeclarationError.new(name, decl, entry.decl)
      when ClassEntry, ModuleEntry
        raise DuplicatedDeclarationError.new(name, decl, *entry.decls.map(&:decl))
      end
    end

    case decl
    when AST::Declarations::ClassAlias
      class_alias_decls[name] = ClassAliasEntry.new(name: name, decl: decl, outer: outer)
    when AST::Declarations::ModuleAlias
      class_alias_decls[name] = ModuleAliasEntry.new(name: name, decl: decl, outer: outer)
    end
  end
end

#inspectObject



798
799
800
801
# File 'lib/rbs/environment.rb', line 798

def inspect
  ivars = %i[@declarations @class_decls @class_alias_decls @interface_decls @type_alias_decls @constant_decls @global_decls]
  "\#<RBS::Environment #{ivars.map { |iv| "#{iv}=(#{instance_variable_get(iv).size} items)"}.join(' ')}>"
end

#interface_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/rbs/environment.rb', line 176

def interface_name?(name)
  interface_decls.key?(name)
end

#module_alias?(name) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
213
214
215
216
# File 'lib/rbs/environment.rb', line 210

def module_alias?(name)
  if decl = class_alias_decls[name]
    decl.decl.is_a?(AST::Declarations::ModuleAlias)
  else
    false
  end
end

#module_class_entry(type_name) ⇒ Object



266
267
268
# File 'lib/rbs/environment.rb', line 266

def module_class_entry(type_name)
  class_entry(type_name) || module_entry(type_name)
end

#module_decl?(name) ⇒ Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/rbs/environment.rb', line 206

def module_decl?(name)
  class_decls[name].is_a?(ModuleEntry)
end

#module_entry(type_name) ⇒ Object



235
236
237
238
239
240
241
242
# File 'lib/rbs/environment.rb', line 235

def module_entry(type_name)
  case
  when (module_entry = class_decls[type_name]).is_a?(ModuleEntry)
    module_entry
  when (module_alias = class_alias_decls[type_name]).is_a?(ModuleAliasEntry)
    module_alias
  end
end

#module_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/rbs/environment.rb', line 184

def module_name?(name)
  class_decls.key?(name) || class_alias_decls.key?(name)
end

#normalize_module_name(name) ⇒ Object



332
333
334
# File 'lib/rbs/environment.rb', line 332

def normalize_module_name(name)
  normalize_module_name?(name) or name
end

#normalize_module_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/rbs/environment.rb', line 336

def normalize_module_name?(name)
  raise "Class/module name is expected: #{name}" unless name.class?
  name = name.absolute! unless name.absolute?

  if @normalize_module_name_cache.key?(name)
    return @normalize_module_name_cache[name]
  end

  unless name.namespace.empty?
    parent = name.namespace.to_type_name
    if normalized_parent = normalize_module_name?(parent)
      type_name = TypeName.new(namespace: normalized_parent.to_namespace, name: name.name)
    else
      @normalize_module_name_cache[name] = nil
      return
    end
  else
    type_name = name
  end

  @normalize_module_name_cache[name] = false

  entry = constant_entry(type_name)

  normalized_type_name =
    case entry
    when ClassEntry, ModuleEntry
      type_name
    when ClassAliasEntry, ModuleAliasEntry
      normalize_module_name?(entry.decl.old_name)
    else
      nil
    end

  @normalize_module_name_cache[name] = normalized_type_name
end

#normalize_type_name(name) ⇒ Object



328
329
330
# File 'lib/rbs/environment.rb', line 328

def normalize_type_name(name)
  normalize_type_name?(name) || name
end

#normalize_type_name!(name) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/rbs/environment.rb', line 297

def normalize_type_name!(name)
  result = normalize_type_name?(name)

  case result
  when TypeName
    result
  when false
    raise "Type name `#{name}` cannot be normalized because it's a cyclic definition"
  when nil
    raise "Type name `#{name}` cannot be normalized because of unknown type name in the path"
  end
end

#normalize_type_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/rbs/environment.rb', line 278

def normalize_type_name?(name)
  return normalize_module_name?(name) if name.class?

  type_name =
    unless name.namespace.empty?
      parent = name.namespace.to_type_name
      parent = normalize_module_name?(parent)
      return parent unless parent

      TypeName.new(namespace: parent.to_namespace, name: name.name)
    else
      name
    end

  if type_name?(type_name)
    type_name
  end
end

#normalized_class_entry(type_name) ⇒ Object



244
245
246
247
248
249
250
251
252
253
# File 'lib/rbs/environment.rb', line 244

def normalized_class_entry(type_name)
  if name = normalize_module_name?(type_name)
    case entry = class_entry(name)
    when ClassEntry, nil
      entry
    when ClassAliasEntry
      raise
    end
  end
end

#normalized_module_class_entry(type_name) ⇒ Object



270
271
272
# File 'lib/rbs/environment.rb', line 270

def normalized_module_class_entry(type_name)
  normalized_class_entry(type_name) || normalized_module_entry(type_name)
end

#normalized_module_entry(type_name) ⇒ Object



255
256
257
258
259
260
261
262
263
264
# File 'lib/rbs/environment.rb', line 255

def normalized_module_entry(type_name)
  if name = normalize_module_name?(type_name)
    case entry = module_entry(name)
    when ModuleEntry, nil
      entry
    when ModuleAliasEntry
      raise
    end
  end
end

#normalized_type_name!(name) ⇒ Object



323
324
325
326
# File 'lib/rbs/environment.rb', line 323

def normalized_type_name!(name)
  normalized_type_name?(name) or raise "Normalized type name is expected but given `#{name}`, which is normalized to `#{normalize_type_name?(name)}`"
  name
end

#normalized_type_name?(type_name) ⇒ Boolean

Returns:

  • (Boolean)


310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/rbs/environment.rb', line 310

def normalized_type_name?(type_name)
  case
  when type_name.interface?
    interface_decls.key?(type_name)
  when type_name.class?
    class_decls.key?(type_name)
  when type_name.alias?
    type_alias_decls.key?(type_name)
  else
    false
  end
end

#resolve_declaration(resolver, map, decl, outer:, prefix:) ⇒ Object



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/rbs/environment.rb', line 537

def resolve_declaration(resolver, map, decl, outer:, prefix:)
  if decl.is_a?(AST::Declarations::Global)
    # @type var decl: AST::Declarations::Global
    return AST::Declarations::Global.new(
      name: decl.name,
      type: absolute_type(resolver, map, decl.type, context: nil),
      location: decl.location,
      comment: decl.comment
    )
  end

  context = resolver_context(*outer)

  case decl
  when AST::Declarations::Class
    outer_context = context
    inner_context = append_context(outer_context, decl)

    outer_ = outer + [decl]
    prefix_ = prefix + decl.name.to_namespace
    AST::Declarations::Class.new(
      name: decl.name.with_prefix(prefix),
      type_params: resolve_type_params(resolver, map, decl.type_params, context: inner_context),
      super_class: decl.super_class&.yield_self do |super_class|
        AST::Declarations::Class::Super.new(
          name: absolute_type_name(resolver, map, super_class.name, context: outer_context),
          args: super_class.args.map {|type| absolute_type(resolver, map, type, context: outer_context) },
          location: super_class.location
        )
      end,
      members: decl.members.map do |member|
        case member
        when AST::Members::Base
          resolve_member(resolver, map, member, context: inner_context)
        when AST::Declarations::Base
          resolve_declaration(
            resolver,
            map,
            member,
            outer: outer_,
            prefix: prefix_
          )
        else
          raise
        end
      end,
      location: decl.location,
      annotations: decl.annotations,
      comment: decl.comment
    )

  when AST::Declarations::Module
    outer_context = context
    inner_context = append_context(outer_context, decl)

    outer_ = outer + [decl]
    prefix_ = prefix + decl.name.to_namespace
    AST::Declarations::Module.new(
      name: decl.name.with_prefix(prefix),
      type_params: resolve_type_params(resolver, map, decl.type_params, context: inner_context),
      self_types: decl.self_types.map do |module_self|
        AST::Declarations::Module::Self.new(
          name: absolute_type_name(resolver, map, module_self.name, context: inner_context),
          args: module_self.args.map {|type| absolute_type(resolver, map, type, context: inner_context) },
          location: module_self.location
        )
      end,
      members: decl.members.map do |member|
        case member
        when AST::Members::Base
          resolve_member(resolver, map, member, context: inner_context)
        when AST::Declarations::Base
          resolve_declaration(
            resolver,
            map,
            member,
            outer: outer_,
            prefix: prefix_
          )
        else
          raise
        end
      end,
      location: decl.location,
      annotations: decl.annotations,
      comment: decl.comment
    )

  when AST::Declarations::Interface
    AST::Declarations::Interface.new(
      name: decl.name.with_prefix(prefix),
      type_params: resolve_type_params(resolver, map, decl.type_params, context: context),
      members: decl.members.map do |member|
        resolve_member(resolver, map, member, context: context)
      end,
      comment: decl.comment,
      location: decl.location,
      annotations: decl.annotations
    )

  when AST::Declarations::TypeAlias
    AST::Declarations::TypeAlias.new(
      name: decl.name.with_prefix(prefix),
      type_params: resolve_type_params(resolver, map, decl.type_params, context: context),
      type: absolute_type(resolver, map, decl.type, context: context),
      location: decl.location,
      annotations: decl.annotations,
      comment: decl.comment
    )

  when AST::Declarations::Constant
    AST::Declarations::Constant.new(
      name: decl.name.with_prefix(prefix),
      type: absolute_type(resolver, map, decl.type, context: context),
      location: decl.location,
      comment: decl.comment
    )

  when AST::Declarations::ClassAlias
    AST::Declarations::ClassAlias.new(
      new_name: decl.new_name.with_prefix(prefix),
      old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
      location: decl.location,
      comment: decl.comment
    )

  when AST::Declarations::ModuleAlias
    AST::Declarations::ModuleAlias.new(
      new_name: decl.new_name.with_prefix(prefix),
      old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
      location: decl.location,
      comment: decl.comment
    )
  end
end

#resolve_member(resolver, map, member, context:) ⇒ Object



673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/rbs/environment.rb', line 673

def resolve_member(resolver, map, member, context:)
  case member
  when AST::Members::MethodDefinition
    AST::Members::MethodDefinition.new(
      name: member.name,
      kind: member.kind,
      overloads: member.overloads.map do |overload|
        overload.update(
          method_type: resolve_method_type(resolver, map, overload.method_type, context: context)
        )
      end,
      comment: member.comment,
      overloading: member.overloading?,
      annotations: member.annotations,
      location: member.location,
      visibility: member.visibility
    )
  when AST::Members::AttrAccessor
    AST::Members::AttrAccessor.new(
      name: member.name,
      type: absolute_type(resolver, map, member.type, context: context),
      kind: member.kind,
      annotations: member.annotations,
      comment: member.comment,
      location: member.location,
      ivar_name: member.ivar_name,
      visibility: member.visibility
    )
  when AST::Members::AttrReader
    AST::Members::AttrReader.new(
      name: member.name,
      type: absolute_type(resolver, map, member.type, context: context),
      kind: member.kind,
      annotations: member.annotations,
      comment: member.comment,
      location: member.location,
      ivar_name: member.ivar_name,
      visibility: member.visibility
    )
  when AST::Members::AttrWriter
    AST::Members::AttrWriter.new(
      name: member.name,
      type: absolute_type(resolver, map, member.type, context: context),
      kind: member.kind,
      annotations: member.annotations,
      comment: member.comment,
      location: member.location,
      ivar_name: member.ivar_name,
      visibility: member.visibility
    )
  when AST::Members::InstanceVariable
    AST::Members::InstanceVariable.new(
      name: member.name,
      type: absolute_type(resolver, map, member.type, context: context),
      comment: member.comment,
      location: member.location
    )
  when AST::Members::ClassInstanceVariable
    AST::Members::ClassInstanceVariable.new(
      name: member.name,
      type: absolute_type(resolver, map, member.type, context: context),
      comment: member.comment,
      location: member.location
    )
  when AST::Members::ClassVariable
    AST::Members::ClassVariable.new(
      name: member.name,
      type: absolute_type(resolver, map, member.type, context: context),
      comment: member.comment,
      location: member.location
    )
  when AST::Members::Include
    AST::Members::Include.new(
      name: absolute_type_name(resolver, map, member.name, context: context),
      args: member.args.map {|type| absolute_type(resolver, map, type, context: context) },
      comment: member.comment,
      location: member.location,
      annotations: member.annotations
    )
  when AST::Members::Extend
    AST::Members::Extend.new(
      name: absolute_type_name(resolver, map, member.name, context: context),
      args: member.args.map {|type| absolute_type(resolver, map, type, context: context) },
      comment: member.comment,
      location: member.location,
      annotations: member.annotations
    )
  when AST::Members::Prepend
    AST::Members::Prepend.new(
      name: absolute_type_name(resolver, map, member.name, context: context),
      args: member.args.map {|type| absolute_type(resolver, map, type, context: context) },
      comment: member.comment,
      location: member.location,
      annotations: member.annotations
    )
  else
    member
  end
end

#resolve_method_type(resolver, map, type, context:) ⇒ Object



773
774
775
776
777
778
779
# File 'lib/rbs/environment.rb', line 773

def resolve_method_type(resolver, map, type, context:)
  type.map_type do |ty|
    absolute_type(resolver, map, ty, context: context)
  end.map_type_bound do |bound|
    _ = absolute_type(resolver, map, bound, context: context)
  end
end

#resolve_type_names(only: nil) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/rbs/environment.rb', line 489

def resolve_type_names(only: nil)
  resolver = Resolver::TypeNameResolver.new(self)
  env = Environment.new

  table = UseMap::Table.new()
  table.known_types.merge(class_decls.keys)
  table.known_types.merge(class_alias_decls.keys)
  table.known_types.merge(type_alias_decls.keys)
  table.known_types.merge(interface_decls.keys)
  table.compute_children

  signatures.each do |buffer, (dirs, decls)|
    map = UseMap.new(table: table)
    dirs.each do |dir|
      dir.clauses.each do |clause|
        map.build_map(clause)
      end
    end

    decls = decls.map do |decl|
      if only && !only.member?(decl)
        decl
      else
        resolve_declaration(resolver, map, decl, outer: [], prefix: Namespace.root)
      end
    end

    env.add_signature(buffer: buffer, directives: dirs, decls: decls)
  end

  env
end

#resolve_type_params(resolver, map, params, context:) ⇒ Object



781
782
783
784
785
# File 'lib/rbs/environment.rb', line 781

def resolve_type_params(resolver, map, params, context:)
  params.map do |param|
    param.map_type {|type| _ = absolute_type(resolver, map, type, context: context) }
  end
end

#resolver_context(*nesting) ⇒ Object



522
523
524
525
526
# File 'lib/rbs/environment.rb', line 522

def resolver_context(*nesting)
  nesting.inject(nil) {|context, decl| #$ Resolver::context
    append_context(context, decl)
  }
end

#type_alias_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/rbs/environment.rb', line 180

def type_alias_name?(name)
  type_alias_decls.key?(name)
end

#type_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
191
192
# File 'lib/rbs/environment.rb', line 188

def type_name?(name)
  interface_name?(name) ||
    type_alias_name?(name) ||
    module_name?(name)
end

#unload(buffers) ⇒ Object



807
808
809
810
811
812
813
814
815
816
# File 'lib/rbs/environment.rb', line 807

def unload(buffers)
  env = Environment.new

  signatures.each do |buf, (dirs, decls)|
    next if buffers.include?(buf)
    env.add_signature(buffer: buf, directives: dirs, decls: decls)
  end

  env
end

#validate_type_paramsObject



483
484
485
486
487
# File 'lib/rbs/environment.rb', line 483

def validate_type_params
  class_decls.each_value do |decl|
    decl.primary
  end
end