rbi 0.3.8 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/lib/rbi/model.rb +208 -162
- data/lib/rbi/parser.rb +1 -1
- data/lib/rbi/printer.rb +152 -89
- data/lib/rbi/rbs/method_type_translator.rb +1 -1
- data/lib/rbi/rbs/type_translator.rb +13 -5
- data/lib/rbi/rbs_printer.rb +8 -3
- data/lib/rbi/rewriters/group_nodes.rb +12 -10
- data/lib/rbi/rewriters/merge_trees.rb +35 -5
- data/lib/rbi/rewriters/nest_non_public_members.rb +22 -13
- data/lib/rbi/rewriters/nest_singleton_methods.rb +15 -7
- data/lib/rbi/rewriters/sort_nodes.rb +18 -21
- data/lib/rbi/rewriters/translate_rbs_sigs.rb +2 -2
- data/lib/rbi/version.rb +1 -1
- data/rbi/rbi.rbi +98 -77
- metadata +6 -10
data/lib/rbi/model.rb
CHANGED
|
@@ -87,12 +87,24 @@ module RBI
|
|
|
87
87
|
# @abstract
|
|
88
88
|
class NodeWithComments < Node
|
|
89
89
|
#: Array[Comment]
|
|
90
|
-
|
|
90
|
+
attr_writer :comments
|
|
91
91
|
|
|
92
|
-
#:
|
|
93
|
-
def
|
|
92
|
+
#: -> Array[Comment]
|
|
93
|
+
def comments
|
|
94
|
+
@comments ||= []
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Returns true if this node has any comments, without allocating
|
|
98
|
+
# an empty array for nodes that have never had comments set.
|
|
99
|
+
#: -> bool
|
|
100
|
+
def comments?
|
|
101
|
+
!@comments.nil? && !@comments.empty?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) -> void
|
|
105
|
+
def initialize(loc: nil, comments: nil)
|
|
94
106
|
super(loc: loc)
|
|
95
|
-
@comments = comments
|
|
107
|
+
@comments = comments #: Array[Comment]?
|
|
96
108
|
end
|
|
97
109
|
|
|
98
110
|
#: -> Array[String]
|
|
@@ -109,8 +121,8 @@ module RBI
|
|
|
109
121
|
#: Array[Node]
|
|
110
122
|
attr_reader :nodes
|
|
111
123
|
|
|
112
|
-
#: (?loc: Loc?, ?comments: Array[Comment]) ?{ (Tree node) -> void } -> void
|
|
113
|
-
def initialize(loc: nil, comments:
|
|
124
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (Tree node) -> void } -> void
|
|
125
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
114
126
|
super(loc: loc, comments: comments)
|
|
115
127
|
@nodes = [] #: Array[Node]
|
|
116
128
|
block&.call(self)
|
|
@@ -136,10 +148,20 @@ module RBI
|
|
|
136
148
|
attr_accessor :strictness
|
|
137
149
|
|
|
138
150
|
#: Array[Comment]
|
|
139
|
-
|
|
151
|
+
attr_writer :comments
|
|
152
|
+
|
|
153
|
+
#: -> Array[Comment]
|
|
154
|
+
def comments
|
|
155
|
+
@comments ||= []
|
|
156
|
+
end
|
|
140
157
|
|
|
141
|
-
#:
|
|
142
|
-
def
|
|
158
|
+
#: -> bool
|
|
159
|
+
def comments?
|
|
160
|
+
!@comments.nil? && !@comments.empty?
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
#: (?strictness: String?, ?comments: Array[Comment]?) ?{ (File file) -> void } -> void
|
|
164
|
+
def initialize(strictness: nil, comments: nil, &block)
|
|
143
165
|
@root = Tree.new #: Tree
|
|
144
166
|
@strictness = strictness
|
|
145
167
|
@comments = comments
|
|
@@ -176,8 +198,8 @@ module RBI
|
|
|
176
198
|
#: String
|
|
177
199
|
attr_accessor :name
|
|
178
200
|
|
|
179
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Module node) -> void } -> void
|
|
180
|
-
def initialize(name, loc: nil, comments:
|
|
201
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (Module node) -> void } -> void
|
|
202
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
181
203
|
super(loc: loc, comments: comments) {}
|
|
182
204
|
@name = name
|
|
183
205
|
block&.call(self)
|
|
@@ -199,8 +221,13 @@ module RBI
|
|
|
199
221
|
#: String?
|
|
200
222
|
attr_accessor :superclass_name
|
|
201
223
|
|
|
202
|
-
#: (
|
|
203
|
-
|
|
224
|
+
#: (
|
|
225
|
+
#| String name,
|
|
226
|
+
#| ?superclass_name: String?,
|
|
227
|
+
#| ?loc: Loc?,
|
|
228
|
+
#| ?comments: Array[Comment]?
|
|
229
|
+
#| ) ?{ (Class node) -> void } -> void
|
|
230
|
+
def initialize(name, superclass_name: nil, loc: nil, comments: nil, &block)
|
|
204
231
|
super(loc: loc, comments: comments) {}
|
|
205
232
|
@name = name
|
|
206
233
|
@superclass_name = superclass_name
|
|
@@ -217,8 +244,8 @@ module RBI
|
|
|
217
244
|
end
|
|
218
245
|
|
|
219
246
|
class SingletonClass < Scope
|
|
220
|
-
#: (?loc: Loc?, ?comments: Array[Comment]) ?{ (SingletonClass node) -> void } -> void
|
|
221
|
-
def initialize(loc: nil, comments:
|
|
247
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (SingletonClass node) -> void } -> void
|
|
248
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
222
249
|
super {}
|
|
223
250
|
block&.call(self)
|
|
224
251
|
end
|
|
@@ -245,9 +272,9 @@ module RBI
|
|
|
245
272
|
#| ?members: Array[Symbol],
|
|
246
273
|
#| ?keyword_init: bool,
|
|
247
274
|
#| ?loc: Loc?,
|
|
248
|
-
#| ?comments: Array[Comment]
|
|
275
|
+
#| ?comments: Array[Comment]?
|
|
249
276
|
#| ) ?{ (Struct struct) -> void } -> void
|
|
250
|
-
def initialize(name, members: [], keyword_init: false, loc: nil, comments:
|
|
277
|
+
def initialize(name, members: [], keyword_init: false, loc: nil, comments: nil, &block)
|
|
251
278
|
super(loc: loc, comments: comments) {}
|
|
252
279
|
@name = name
|
|
253
280
|
@members = members
|
|
@@ -270,8 +297,8 @@ module RBI
|
|
|
270
297
|
#: String
|
|
271
298
|
attr_reader :name, :value
|
|
272
299
|
|
|
273
|
-
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Const node) -> void } -> void
|
|
274
|
-
def initialize(name, value, loc: nil, comments:
|
|
300
|
+
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (Const node) -> void } -> void
|
|
301
|
+
def initialize(name, value, loc: nil, comments: nil, &block)
|
|
275
302
|
super(loc: loc, comments: comments)
|
|
276
303
|
@name = name
|
|
277
304
|
@value = value
|
|
@@ -302,22 +329,32 @@ module RBI
|
|
|
302
329
|
#: Visibility
|
|
303
330
|
attr_accessor :visibility
|
|
304
331
|
|
|
332
|
+
#: -> Array[Sig]
|
|
333
|
+
def sigs
|
|
334
|
+
@sigs ||= []
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
#: -> bool
|
|
338
|
+
def sigs?
|
|
339
|
+
!@sigs.nil? && !@sigs.empty?
|
|
340
|
+
end
|
|
341
|
+
|
|
305
342
|
#: Array[Sig]
|
|
306
|
-
|
|
343
|
+
attr_writer :sigs
|
|
307
344
|
|
|
308
345
|
#: (
|
|
309
346
|
#| Symbol name,
|
|
310
347
|
#| Array[Symbol] names,
|
|
311
348
|
#| ?visibility: Visibility,
|
|
312
|
-
#| ?sigs: Array[Sig]
|
|
349
|
+
#| ?sigs: Array[Sig]?,
|
|
313
350
|
#| ?loc: Loc?,
|
|
314
|
-
#| ?comments: Array[Comment]
|
|
351
|
+
#| ?comments: Array[Comment]?
|
|
315
352
|
#| ) -> void
|
|
316
|
-
def initialize(name, names, visibility: Public
|
|
353
|
+
def initialize(name, names, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil)
|
|
317
354
|
super(loc: loc, comments: comments)
|
|
318
355
|
@names = [name, *names] #: Array[Symbol]
|
|
319
356
|
@visibility = visibility
|
|
320
|
-
@sigs = sigs
|
|
357
|
+
@sigs = sigs #: Array[Sig]?
|
|
321
358
|
end
|
|
322
359
|
|
|
323
360
|
# @abstract
|
|
@@ -330,11 +367,11 @@ module RBI
|
|
|
330
367
|
#| Symbol name,
|
|
331
368
|
#| *Symbol names,
|
|
332
369
|
#| ?visibility: Visibility,
|
|
333
|
-
#| ?sigs: Array[Sig]
|
|
370
|
+
#| ?sigs: Array[Sig]?,
|
|
334
371
|
#| ?loc: Loc?,
|
|
335
|
-
#| ?comments: Array[Comment]
|
|
372
|
+
#| ?comments: Array[Comment]?
|
|
336
373
|
#| ) ?{ (AttrAccessor node) -> void } -> void
|
|
337
|
-
def initialize(name, *names, visibility: Public
|
|
374
|
+
def initialize(name, *names, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block)
|
|
338
375
|
super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
|
|
339
376
|
block&.call(self)
|
|
340
377
|
end
|
|
@@ -359,11 +396,11 @@ module RBI
|
|
|
359
396
|
#| Symbol name,
|
|
360
397
|
#| *Symbol names,
|
|
361
398
|
#| ?visibility: Visibility,
|
|
362
|
-
#| ?sigs: Array[Sig]
|
|
399
|
+
#| ?sigs: Array[Sig]?,
|
|
363
400
|
#| ?loc: Loc?,
|
|
364
|
-
#| ?comments: Array[Comment]
|
|
401
|
+
#| ?comments: Array[Comment]?
|
|
365
402
|
#| ) ?{ (AttrReader node) -> void } -> void
|
|
366
|
-
def initialize(name, *names, visibility: Public
|
|
403
|
+
def initialize(name, *names, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block)
|
|
367
404
|
super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
|
|
368
405
|
block&.call(self)
|
|
369
406
|
end
|
|
@@ -388,11 +425,11 @@ module RBI
|
|
|
388
425
|
#| Symbol name,
|
|
389
426
|
#| *Symbol names,
|
|
390
427
|
#| ?visibility: Visibility,
|
|
391
|
-
#| ?sigs: Array[Sig]
|
|
428
|
+
#| ?sigs: Array[Sig]?,
|
|
392
429
|
#| ?loc: Loc?,
|
|
393
|
-
#| ?comments: Array[Comment]
|
|
430
|
+
#| ?comments: Array[Comment]?
|
|
394
431
|
#| ) ?{ (AttrWriter node) -> void } -> void
|
|
395
|
-
def initialize(name, *names, visibility: Public
|
|
432
|
+
def initialize(name, *names, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block)
|
|
396
433
|
super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
|
|
397
434
|
block&.call(self)
|
|
398
435
|
end
|
|
@@ -418,8 +455,10 @@ module RBI
|
|
|
418
455
|
#: String
|
|
419
456
|
attr_accessor :name
|
|
420
457
|
|
|
421
|
-
#: Array[Param]
|
|
422
|
-
|
|
458
|
+
#: -> Array[Param]
|
|
459
|
+
def params
|
|
460
|
+
@params ||= []
|
|
461
|
+
end
|
|
423
462
|
|
|
424
463
|
#: bool
|
|
425
464
|
attr_accessor :is_singleton
|
|
@@ -427,85 +466,95 @@ module RBI
|
|
|
427
466
|
#: Visibility
|
|
428
467
|
attr_accessor :visibility
|
|
429
468
|
|
|
469
|
+
#: -> Array[Sig]
|
|
470
|
+
def sigs
|
|
471
|
+
@sigs ||= []
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
#: -> bool
|
|
475
|
+
def sigs?
|
|
476
|
+
!@sigs.nil? && !@sigs.empty?
|
|
477
|
+
end
|
|
478
|
+
|
|
430
479
|
#: Array[Sig]
|
|
431
|
-
|
|
480
|
+
attr_writer :sigs
|
|
432
481
|
|
|
433
482
|
#: (
|
|
434
483
|
#| String name,
|
|
435
|
-
#| ?params: Array[Param]
|
|
484
|
+
#| ?params: Array[Param]?,
|
|
436
485
|
#| ?is_singleton: bool,
|
|
437
486
|
#| ?visibility: Visibility,
|
|
438
|
-
#| ?sigs: Array[Sig]
|
|
487
|
+
#| ?sigs: Array[Sig]?,
|
|
439
488
|
#| ?loc: Loc?,
|
|
440
|
-
#| ?comments: Array[Comment]
|
|
489
|
+
#| ?comments: Array[Comment]?
|
|
441
490
|
#| ) ?{ (Method node) -> void } -> void
|
|
442
491
|
def initialize(
|
|
443
492
|
name,
|
|
444
|
-
params:
|
|
493
|
+
params: nil,
|
|
445
494
|
is_singleton: false,
|
|
446
|
-
visibility: Public
|
|
447
|
-
sigs:
|
|
495
|
+
visibility: Public::DEFAULT,
|
|
496
|
+
sigs: nil,
|
|
448
497
|
loc: nil,
|
|
449
|
-
comments:
|
|
498
|
+
comments: nil,
|
|
450
499
|
&block
|
|
451
500
|
)
|
|
452
501
|
super(loc: loc, comments: comments)
|
|
453
502
|
@name = name
|
|
454
|
-
@params = params
|
|
503
|
+
@params = params #: Array[Param]?
|
|
455
504
|
@is_singleton = is_singleton
|
|
456
505
|
@visibility = visibility
|
|
457
|
-
@sigs = sigs
|
|
506
|
+
@sigs = sigs #: Array[Sig]?
|
|
458
507
|
block&.call(self)
|
|
459
508
|
end
|
|
460
509
|
|
|
461
510
|
#: (Param param) -> void
|
|
462
511
|
def <<(param)
|
|
463
|
-
|
|
512
|
+
params << param
|
|
464
513
|
end
|
|
465
514
|
|
|
466
515
|
#: (String name) -> void
|
|
467
516
|
def add_param(name)
|
|
468
|
-
|
|
517
|
+
params << ReqParam.new(name)
|
|
469
518
|
end
|
|
470
519
|
|
|
471
520
|
#: (String name, String default_value) -> void
|
|
472
521
|
def add_opt_param(name, default_value)
|
|
473
|
-
|
|
522
|
+
params << OptParam.new(name, default_value)
|
|
474
523
|
end
|
|
475
524
|
|
|
476
525
|
#: (String name) -> void
|
|
477
526
|
def add_rest_param(name)
|
|
478
|
-
|
|
527
|
+
params << RestParam.new(name)
|
|
479
528
|
end
|
|
480
529
|
|
|
481
530
|
#: (String name) -> void
|
|
482
531
|
def add_kw_param(name)
|
|
483
|
-
|
|
532
|
+
params << KwParam.new(name)
|
|
484
533
|
end
|
|
485
534
|
|
|
486
535
|
#: (String name, String default_value) -> void
|
|
487
536
|
def add_kw_opt_param(name, default_value)
|
|
488
|
-
|
|
537
|
+
params << KwOptParam.new(name, default_value)
|
|
489
538
|
end
|
|
490
539
|
|
|
491
540
|
#: (String name) -> void
|
|
492
541
|
def add_kw_rest_param(name)
|
|
493
|
-
|
|
542
|
+
params << KwRestParam.new(name)
|
|
494
543
|
end
|
|
495
544
|
|
|
496
545
|
#: (String name) -> void
|
|
497
546
|
def add_block_param(name)
|
|
498
|
-
|
|
547
|
+
params << BlockParam.new(name)
|
|
499
548
|
end
|
|
500
549
|
|
|
501
550
|
#: (
|
|
502
|
-
#| ?params: Array[SigParam]
|
|
551
|
+
#| ?params: Array[SigParam]?,
|
|
503
552
|
#| ?return_type: (String | Type),
|
|
504
553
|
#| ?is_abstract: bool,
|
|
505
554
|
#| ?is_override: bool,
|
|
506
555
|
#| ?is_overridable: bool,
|
|
507
556
|
#| ?is_final: bool,
|
|
508
|
-
#| ?type_params: Array[String]
|
|
557
|
+
#| ?type_params: Array[String]?,
|
|
509
558
|
#| ?checked: Symbol?) ?{ (Sig node) -> void } -> void
|
|
510
559
|
def add_sig(
|
|
511
560
|
params: [],
|
|
@@ -529,7 +578,7 @@ module RBI
|
|
|
529
578
|
checked: checked,
|
|
530
579
|
&block
|
|
531
580
|
)
|
|
532
|
-
|
|
581
|
+
sigs << sig
|
|
533
582
|
end
|
|
534
583
|
|
|
535
584
|
#: -> String
|
|
@@ -553,10 +602,11 @@ module RBI
|
|
|
553
602
|
#: String
|
|
554
603
|
attr_reader :name
|
|
555
604
|
|
|
556
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) -> void
|
|
557
|
-
def initialize(name, loc: nil, comments:
|
|
605
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) -> void
|
|
606
|
+
def initialize(name, loc: nil, comments: nil)
|
|
558
607
|
super(loc: loc, comments: comments)
|
|
559
608
|
@name = name
|
|
609
|
+
@anonymous = name.start_with?("_") #: bool
|
|
560
610
|
end
|
|
561
611
|
|
|
562
612
|
# @override
|
|
@@ -564,18 +614,24 @@ module RBI
|
|
|
564
614
|
def to_s
|
|
565
615
|
name
|
|
566
616
|
end
|
|
567
|
-
end
|
|
568
617
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
super(name, loc: loc, comments: comments)
|
|
573
|
-
block&.call(self)
|
|
618
|
+
#: -> bool
|
|
619
|
+
def anonymous?
|
|
620
|
+
@anonymous
|
|
574
621
|
end
|
|
575
622
|
|
|
576
623
|
#: (Object? other) -> bool
|
|
577
624
|
def ==(other)
|
|
578
|
-
|
|
625
|
+
self.class === other &&
|
|
626
|
+
(name == other.name || anonymous? || other.anonymous?)
|
|
627
|
+
end
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
class ReqParam < Param
|
|
631
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (ReqParam node) -> void } -> void
|
|
632
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
633
|
+
super(name, loc: loc, comments: comments)
|
|
634
|
+
block&.call(self)
|
|
579
635
|
end
|
|
580
636
|
end
|
|
581
637
|
|
|
@@ -583,22 +639,17 @@ module RBI
|
|
|
583
639
|
#: String
|
|
584
640
|
attr_reader :value
|
|
585
641
|
|
|
586
|
-
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]) ?{ (OptParam node) -> void } -> void
|
|
587
|
-
def initialize(name, value, loc: nil, comments:
|
|
642
|
+
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (OptParam node) -> void } -> void
|
|
643
|
+
def initialize(name, value, loc: nil, comments: nil, &block)
|
|
588
644
|
super(name, loc: loc, comments: comments)
|
|
589
645
|
@value = value
|
|
590
646
|
block&.call(self)
|
|
591
647
|
end
|
|
592
|
-
|
|
593
|
-
#: (Object? other) -> bool
|
|
594
|
-
def ==(other)
|
|
595
|
-
OptParam === other && name == other.name
|
|
596
|
-
end
|
|
597
648
|
end
|
|
598
649
|
|
|
599
650
|
class RestParam < Param
|
|
600
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (RestParam node) -> void } -> void
|
|
601
|
-
def initialize(name, loc: nil, comments:
|
|
651
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (RestParam node) -> void } -> void
|
|
652
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
602
653
|
super(name, loc: loc, comments: comments)
|
|
603
654
|
block&.call(self)
|
|
604
655
|
end
|
|
@@ -608,16 +659,11 @@ module RBI
|
|
|
608
659
|
def to_s
|
|
609
660
|
"*#{name}"
|
|
610
661
|
end
|
|
611
|
-
|
|
612
|
-
#: (Object? other) -> bool
|
|
613
|
-
def ==(other)
|
|
614
|
-
RestParam === other && name == other.name
|
|
615
|
-
end
|
|
616
662
|
end
|
|
617
663
|
|
|
618
664
|
class KwParam < Param
|
|
619
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (KwParam node) -> void } -> void
|
|
620
|
-
def initialize(name, loc: nil, comments:
|
|
665
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (KwParam node) -> void } -> void
|
|
666
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
621
667
|
super(name, loc: loc, comments: comments)
|
|
622
668
|
block&.call(self)
|
|
623
669
|
end
|
|
@@ -627,19 +673,14 @@ module RBI
|
|
|
627
673
|
def to_s
|
|
628
674
|
"#{name}:"
|
|
629
675
|
end
|
|
630
|
-
|
|
631
|
-
#: (Object? other) -> bool
|
|
632
|
-
def ==(other)
|
|
633
|
-
KwParam === other && name == other.name
|
|
634
|
-
end
|
|
635
676
|
end
|
|
636
677
|
|
|
637
678
|
class KwOptParam < Param
|
|
638
679
|
#: String
|
|
639
680
|
attr_reader :value
|
|
640
681
|
|
|
641
|
-
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]) ?{ (KwOptParam node) -> void } -> void
|
|
642
|
-
def initialize(name, value, loc: nil, comments:
|
|
682
|
+
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (KwOptParam node) -> void } -> void
|
|
683
|
+
def initialize(name, value, loc: nil, comments: nil, &block)
|
|
643
684
|
super(name, loc: loc, comments: comments)
|
|
644
685
|
@value = value
|
|
645
686
|
block&.call(self)
|
|
@@ -650,16 +691,11 @@ module RBI
|
|
|
650
691
|
def to_s
|
|
651
692
|
"#{name}:"
|
|
652
693
|
end
|
|
653
|
-
|
|
654
|
-
#: (Object? other) -> bool
|
|
655
|
-
def ==(other)
|
|
656
|
-
KwOptParam === other && name == other.name
|
|
657
|
-
end
|
|
658
694
|
end
|
|
659
695
|
|
|
660
696
|
class KwRestParam < Param
|
|
661
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (KwRestParam node) -> void } -> void
|
|
662
|
-
def initialize(name, loc: nil, comments:
|
|
697
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (KwRestParam node) -> void } -> void
|
|
698
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
663
699
|
super(name, loc: loc, comments: comments)
|
|
664
700
|
block&.call(self)
|
|
665
701
|
end
|
|
@@ -669,16 +705,11 @@ module RBI
|
|
|
669
705
|
def to_s
|
|
670
706
|
"**#{name}:"
|
|
671
707
|
end
|
|
672
|
-
|
|
673
|
-
#: (Object? other) -> bool
|
|
674
|
-
def ==(other)
|
|
675
|
-
KwRestParam === other && name == other.name
|
|
676
|
-
end
|
|
677
708
|
end
|
|
678
709
|
|
|
679
710
|
class BlockParam < Param
|
|
680
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (BlockParam node) -> void } -> void
|
|
681
|
-
def initialize(name, loc: nil, comments:
|
|
711
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (BlockParam node) -> void } -> void
|
|
712
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
682
713
|
super(name, loc: loc, comments: comments)
|
|
683
714
|
block&.call(self)
|
|
684
715
|
end
|
|
@@ -688,11 +719,6 @@ module RBI
|
|
|
688
719
|
def to_s
|
|
689
720
|
"&#{name}"
|
|
690
721
|
end
|
|
691
|
-
|
|
692
|
-
#: (Object? other) -> bool
|
|
693
|
-
def ==(other)
|
|
694
|
-
BlockParam === other && name == other.name
|
|
695
|
-
end
|
|
696
722
|
end
|
|
697
723
|
|
|
698
724
|
# Mixins
|
|
@@ -702,16 +728,16 @@ module RBI
|
|
|
702
728
|
#: Array[String]
|
|
703
729
|
attr_reader :names
|
|
704
730
|
|
|
705
|
-
#: (String name, Array[String] names, ?loc: Loc?, ?comments: Array[Comment]) -> void
|
|
706
|
-
def initialize(name, names, loc: nil, comments:
|
|
731
|
+
#: (String name, Array[String] names, ?loc: Loc?, ?comments: Array[Comment]?) -> void
|
|
732
|
+
def initialize(name, names, loc: nil, comments: nil)
|
|
707
733
|
super(loc: loc, comments: comments)
|
|
708
734
|
@names = [name, *names] #: Array[String]
|
|
709
735
|
end
|
|
710
736
|
end
|
|
711
737
|
|
|
712
738
|
class Include < Mixin
|
|
713
|
-
#: (String name, *String names, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Include node) -> void } -> void
|
|
714
|
-
def initialize(name, *names, loc: nil, comments:
|
|
739
|
+
#: (String name, *String names, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (Include node) -> void } -> void
|
|
740
|
+
def initialize(name, *names, loc: nil, comments: nil, &block)
|
|
715
741
|
super(name, names, loc: loc, comments: comments)
|
|
716
742
|
block&.call(self)
|
|
717
743
|
end
|
|
@@ -724,8 +750,8 @@ module RBI
|
|
|
724
750
|
end
|
|
725
751
|
|
|
726
752
|
class Extend < Mixin
|
|
727
|
-
#: (String name, *String names, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Extend node) -> void } -> void
|
|
728
|
-
def initialize(name, *names, loc: nil, comments:
|
|
753
|
+
#: (String name, *String names, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (Extend node) -> void } -> void
|
|
754
|
+
def initialize(name, *names, loc: nil, comments: nil, &block)
|
|
729
755
|
super(name, names, loc: loc, comments: comments)
|
|
730
756
|
block&.call(self)
|
|
731
757
|
end
|
|
@@ -744,8 +770,8 @@ module RBI
|
|
|
744
770
|
#: Symbol
|
|
745
771
|
attr_reader :visibility
|
|
746
772
|
|
|
747
|
-
#: (Symbol visibility, ?loc: Loc?, ?comments: Array[Comment]) -> void
|
|
748
|
-
def initialize(visibility, loc: nil, comments:
|
|
773
|
+
#: (Symbol visibility, ?loc: Loc?, ?comments: Array[Comment]?) -> void
|
|
774
|
+
def initialize(visibility, loc: nil, comments: nil)
|
|
749
775
|
super(loc: loc, comments: comments)
|
|
750
776
|
@visibility = visibility
|
|
751
777
|
end
|
|
@@ -774,24 +800,27 @@ module RBI
|
|
|
774
800
|
end
|
|
775
801
|
|
|
776
802
|
class Public < Visibility
|
|
777
|
-
#: (?loc: Loc?, ?comments: Array[Comment]) ?{ (Public node) -> void } -> void
|
|
778
|
-
def initialize(loc: nil, comments:
|
|
803
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (Public node) -> void } -> void
|
|
804
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
779
805
|
super(:public, loc: loc, comments: comments)
|
|
780
806
|
block&.call(self)
|
|
781
807
|
end
|
|
808
|
+
|
|
809
|
+
# Shared default instance to avoid allocating a new Public on every Method/Attr creation.
|
|
810
|
+
DEFAULT = new.freeze #: Public
|
|
782
811
|
end
|
|
783
812
|
|
|
784
813
|
class Protected < Visibility
|
|
785
|
-
#: (?loc: Loc?, ?comments: Array[Comment]) ?{ (Protected node) -> void } -> void
|
|
786
|
-
def initialize(loc: nil, comments:
|
|
814
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (Protected node) -> void } -> void
|
|
815
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
787
816
|
super(:protected, loc: loc, comments: comments)
|
|
788
817
|
block&.call(self)
|
|
789
818
|
end
|
|
790
819
|
end
|
|
791
820
|
|
|
792
821
|
class Private < Visibility
|
|
793
|
-
#: (?loc: Loc?, ?comments: Array[Comment]) ?{ (Private node) -> void } -> void
|
|
794
|
-
def initialize(loc: nil, comments:
|
|
822
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (Private node) -> void } -> void
|
|
823
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
795
824
|
super(:private, loc: loc, comments: comments)
|
|
796
825
|
block&.call(self)
|
|
797
826
|
end
|
|
@@ -806,8 +835,8 @@ module RBI
|
|
|
806
835
|
#: Array[Arg]
|
|
807
836
|
attr_reader :args
|
|
808
837
|
|
|
809
|
-
#: (String method, ?Array[Arg] args, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Send node) -> void } -> void
|
|
810
|
-
def initialize(method, args = [], loc: nil, comments:
|
|
838
|
+
#: (String method, ?Array[Arg] args, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (Send node) -> void } -> void
|
|
839
|
+
def initialize(method, args = [], loc: nil, comments: nil, &block)
|
|
811
840
|
super(loc: loc, comments: comments)
|
|
812
841
|
@method = method
|
|
813
842
|
@args = args
|
|
@@ -875,8 +904,10 @@ module RBI
|
|
|
875
904
|
# Sorbet's sigs
|
|
876
905
|
|
|
877
906
|
class Sig < NodeWithComments
|
|
878
|
-
#: Array[SigParam]
|
|
879
|
-
|
|
907
|
+
#: -> Array[SigParam]
|
|
908
|
+
def params
|
|
909
|
+
@params ||= []
|
|
910
|
+
end
|
|
880
911
|
|
|
881
912
|
#: (Type | String)
|
|
882
913
|
attr_accessor :return_type
|
|
@@ -902,14 +933,21 @@ module RBI
|
|
|
902
933
|
#: bool
|
|
903
934
|
attr_accessor :without_runtime
|
|
904
935
|
|
|
905
|
-
#: Array[String]
|
|
906
|
-
|
|
936
|
+
#: -> Array[String]
|
|
937
|
+
def type_params
|
|
938
|
+
@type_params ||= []
|
|
939
|
+
end
|
|
940
|
+
|
|
941
|
+
#: -> bool
|
|
942
|
+
def type_params?
|
|
943
|
+
!@type_params.nil? && !@type_params.empty?
|
|
944
|
+
end
|
|
907
945
|
|
|
908
946
|
#: Symbol?
|
|
909
947
|
attr_accessor :checked
|
|
910
948
|
|
|
911
949
|
#: (
|
|
912
|
-
#| ?params: Array[SigParam]
|
|
950
|
+
#| ?params: Array[SigParam]?,
|
|
913
951
|
#| ?return_type: (Type | String),
|
|
914
952
|
#| ?is_abstract: bool,
|
|
915
953
|
#| ?is_override: bool,
|
|
@@ -918,13 +956,13 @@ module RBI
|
|
|
918
956
|
#| ?allow_incompatible_override: bool,
|
|
919
957
|
#| ?allow_incompatible_override_visibility: bool,
|
|
920
958
|
#| ?without_runtime: bool,
|
|
921
|
-
#| ?type_params: Array[String]
|
|
959
|
+
#| ?type_params: Array[String]?,
|
|
922
960
|
#| ?checked: Symbol?,
|
|
923
961
|
#| ?loc: Loc?,
|
|
924
|
-
#| ?comments: Array[Comment]
|
|
962
|
+
#| ?comments: Array[Comment]?
|
|
925
963
|
#| ) ?{ (Sig node) -> void } -> void
|
|
926
964
|
def initialize(
|
|
927
|
-
params:
|
|
965
|
+
params: nil,
|
|
928
966
|
return_type: "void",
|
|
929
967
|
is_abstract: false,
|
|
930
968
|
is_override: false,
|
|
@@ -933,14 +971,14 @@ module RBI
|
|
|
933
971
|
allow_incompatible_override: false,
|
|
934
972
|
allow_incompatible_override_visibility: false,
|
|
935
973
|
without_runtime: false,
|
|
936
|
-
type_params:
|
|
974
|
+
type_params: nil,
|
|
937
975
|
checked: nil,
|
|
938
976
|
loc: nil,
|
|
939
|
-
comments:
|
|
977
|
+
comments: nil,
|
|
940
978
|
&block
|
|
941
979
|
)
|
|
942
980
|
super(loc: loc, comments: comments)
|
|
943
|
-
@params = params
|
|
981
|
+
@params = params #: Array[SigParam]?
|
|
944
982
|
@return_type = return_type
|
|
945
983
|
@is_abstract = is_abstract
|
|
946
984
|
@is_override = is_override
|
|
@@ -949,19 +987,19 @@ module RBI
|
|
|
949
987
|
@allow_incompatible_override = allow_incompatible_override
|
|
950
988
|
@allow_incompatible_override_visibility = allow_incompatible_override_visibility
|
|
951
989
|
@without_runtime = without_runtime
|
|
952
|
-
@type_params = type_params
|
|
990
|
+
@type_params = type_params #: Array[String]?
|
|
953
991
|
@checked = checked
|
|
954
992
|
block&.call(self)
|
|
955
993
|
end
|
|
956
994
|
|
|
957
995
|
#: (SigParam param) -> void
|
|
958
996
|
def <<(param)
|
|
959
|
-
|
|
997
|
+
params << param
|
|
960
998
|
end
|
|
961
999
|
|
|
962
1000
|
#: (String name, (Type | String) type) -> void
|
|
963
1001
|
def add_param(name, type)
|
|
964
|
-
|
|
1002
|
+
params << SigParam.new(name, type)
|
|
965
1003
|
end
|
|
966
1004
|
|
|
967
1005
|
#: (Object other) -> bool
|
|
@@ -981,25 +1019,33 @@ module RBI
|
|
|
981
1019
|
#: (Type | String)
|
|
982
1020
|
attr_reader :type
|
|
983
1021
|
|
|
984
|
-
#: (String name, (Type | String) type, ?loc: Loc?, ?comments: Array[Comment]) ?{ (SigParam node) -> void } -> void
|
|
985
|
-
def initialize(name, type, loc: nil, comments:
|
|
1022
|
+
#: (String name, (Type | String) type, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (SigParam node) -> void } -> void
|
|
1023
|
+
def initialize(name, type, loc: nil, comments: nil, &block)
|
|
986
1024
|
super(loc: loc, comments: comments)
|
|
987
1025
|
@name = name
|
|
1026
|
+
@anonymous = name.start_with?("_") #: bool
|
|
988
1027
|
@type = type
|
|
989
1028
|
block&.call(self)
|
|
990
1029
|
end
|
|
991
1030
|
|
|
1031
|
+
#: -> bool
|
|
1032
|
+
def anonymous?
|
|
1033
|
+
@anonymous
|
|
1034
|
+
end
|
|
1035
|
+
|
|
992
1036
|
#: (Object other) -> bool
|
|
993
1037
|
def ==(other)
|
|
994
|
-
other.is_a?(SigParam) &&
|
|
1038
|
+
other.is_a?(SigParam) &&
|
|
1039
|
+
(name == other.name || anonymous? || other.anonymous?) &&
|
|
1040
|
+
type.to_s == other.type.to_s
|
|
995
1041
|
end
|
|
996
1042
|
end
|
|
997
1043
|
|
|
998
1044
|
# Sorbet's T::Struct
|
|
999
1045
|
|
|
1000
1046
|
class TStruct < Class
|
|
1001
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TStruct klass) -> void } -> void
|
|
1002
|
-
def initialize(name, loc: nil, comments:
|
|
1047
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (TStruct klass) -> void } -> void
|
|
1048
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
1003
1049
|
super(name, superclass_name: "::T::Struct", loc: loc, comments: comments) {}
|
|
1004
1050
|
block&.call(self)
|
|
1005
1051
|
end
|
|
@@ -1016,8 +1062,8 @@ module RBI
|
|
|
1016
1062
|
#: String?
|
|
1017
1063
|
attr_accessor :default
|
|
1018
1064
|
|
|
1019
|
-
#: (String name, (Type | String) type, ?default: String?, ?loc: Loc?, ?comments: Array[Comment]) -> void
|
|
1020
|
-
def initialize(name, type, default: nil, loc: nil, comments:
|
|
1065
|
+
#: (String name, (Type | String) type, ?default: String?, ?loc: Loc?, ?comments: Array[Comment]?) -> void
|
|
1066
|
+
def initialize(name, type, default: nil, loc: nil, comments: nil)
|
|
1021
1067
|
super(loc: loc, comments: comments)
|
|
1022
1068
|
@name = name
|
|
1023
1069
|
@type = type
|
|
@@ -1035,9 +1081,9 @@ module RBI
|
|
|
1035
1081
|
#| (Type | String) type,
|
|
1036
1082
|
#| ?default: String?,
|
|
1037
1083
|
#| ?loc: Loc?,
|
|
1038
|
-
#| ?comments: Array[Comment]
|
|
1084
|
+
#| ?comments: Array[Comment]?
|
|
1039
1085
|
#| ) ?{ (TStructConst node) -> void } -> void
|
|
1040
|
-
def initialize(name, type, default: nil, loc: nil, comments:
|
|
1086
|
+
def initialize(name, type, default: nil, loc: nil, comments: nil, &block)
|
|
1041
1087
|
super(name, type, default: default, loc: loc, comments: comments)
|
|
1042
1088
|
block&.call(self)
|
|
1043
1089
|
end
|
|
@@ -1062,9 +1108,9 @@ module RBI
|
|
|
1062
1108
|
#| (Type | String) type,
|
|
1063
1109
|
#| ?default: String?,
|
|
1064
1110
|
#| ?loc: Loc?,
|
|
1065
|
-
#| ?comments: Array[Comment]
|
|
1111
|
+
#| ?comments: Array[Comment]?
|
|
1066
1112
|
#| ) ?{ (TStructProp node) -> void } -> void
|
|
1067
|
-
def initialize(name, type, default: nil, loc: nil, comments:
|
|
1113
|
+
def initialize(name, type, default: nil, loc: nil, comments: nil, &block)
|
|
1068
1114
|
super(name, type, default: default, loc: loc, comments: comments)
|
|
1069
1115
|
block&.call(self)
|
|
1070
1116
|
end
|
|
@@ -1086,16 +1132,16 @@ module RBI
|
|
|
1086
1132
|
# Sorbet's T::Enum
|
|
1087
1133
|
|
|
1088
1134
|
class TEnum < Class
|
|
1089
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TEnum klass) -> void } -> void
|
|
1090
|
-
def initialize(name, loc: nil, comments:
|
|
1135
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (TEnum klass) -> void } -> void
|
|
1136
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
1091
1137
|
super(name, superclass_name: "::T::Enum", loc: loc, comments: comments) {}
|
|
1092
1138
|
block&.call(self)
|
|
1093
1139
|
end
|
|
1094
1140
|
end
|
|
1095
1141
|
|
|
1096
1142
|
class TEnumBlock < Scope
|
|
1097
|
-
#: (?loc: Loc?, ?comments: Array[Comment]) ?{ (TEnumBlock node) -> void } -> void
|
|
1098
|
-
def initialize(loc: nil, comments:
|
|
1143
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (TEnumBlock node) -> void } -> void
|
|
1144
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
1099
1145
|
super {}
|
|
1100
1146
|
block&.call(self)
|
|
1101
1147
|
end
|
|
@@ -1117,8 +1163,8 @@ module RBI
|
|
|
1117
1163
|
#: String
|
|
1118
1164
|
attr_reader :name
|
|
1119
1165
|
|
|
1120
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TEnumValue node) -> void } -> void
|
|
1121
|
-
def initialize(name, loc: nil, comments:
|
|
1166
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (TEnumValue node) -> void } -> void
|
|
1167
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
1122
1168
|
super(loc: loc, comments: comments)
|
|
1123
1169
|
@name = name
|
|
1124
1170
|
block&.call(self)
|
|
@@ -1142,8 +1188,8 @@ module RBI
|
|
|
1142
1188
|
#: String
|
|
1143
1189
|
attr_reader :name
|
|
1144
1190
|
|
|
1145
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Helper node) -> void } -> void
|
|
1146
|
-
def initialize(name, loc: nil, comments:
|
|
1191
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (Helper node) -> void } -> void
|
|
1192
|
+
def initialize(name, loc: nil, comments: nil, &block)
|
|
1147
1193
|
super(loc: loc, comments: comments)
|
|
1148
1194
|
@name = name
|
|
1149
1195
|
block&.call(self)
|
|
@@ -1160,8 +1206,8 @@ module RBI
|
|
|
1160
1206
|
#: String
|
|
1161
1207
|
attr_reader :name, :value
|
|
1162
1208
|
|
|
1163
|
-
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]) ?{ (TypeMember node) -> void } -> void
|
|
1164
|
-
def initialize(name, value, loc: nil, comments:
|
|
1209
|
+
#: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (TypeMember node) -> void } -> void
|
|
1210
|
+
def initialize(name, value, loc: nil, comments: nil, &block)
|
|
1165
1211
|
super(loc: loc, comments: comments)
|
|
1166
1212
|
@name = name
|
|
1167
1213
|
@value = value
|
|
@@ -1187,9 +1233,9 @@ module RBI
|
|
|
1187
1233
|
#| String name,
|
|
1188
1234
|
#| *String names,
|
|
1189
1235
|
#| ?loc: Loc?,
|
|
1190
|
-
#| ?comments: Array[Comment]
|
|
1236
|
+
#| ?comments: Array[Comment]?
|
|
1191
1237
|
#| ) ?{ (MixesInClassMethods node) -> void } -> void
|
|
1192
|
-
def initialize(name, *names, loc: nil, comments:
|
|
1238
|
+
def initialize(name, *names, loc: nil, comments: nil, &block)
|
|
1193
1239
|
super(name, names, loc: loc, comments: comments)
|
|
1194
1240
|
block&.call(self)
|
|
1195
1241
|
end
|
|
@@ -1205,8 +1251,8 @@ module RBI
|
|
|
1205
1251
|
#: String
|
|
1206
1252
|
attr_reader :name
|
|
1207
1253
|
|
|
1208
|
-
#: (String name, ?loc: Loc?, ?comments: Array[Comment]) -> void
|
|
1209
|
-
def initialize(name, loc: nil, comments:
|
|
1254
|
+
#: (String name, ?loc: Loc?, ?comments: Array[Comment]?) -> void
|
|
1255
|
+
def initialize(name, loc: nil, comments: nil)
|
|
1210
1256
|
super(loc: loc, comments: comments)
|
|
1211
1257
|
@name = name
|
|
1212
1258
|
end
|