rbi 0.2.2 → 0.3.3
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/Gemfile +2 -1
- data/lib/rbi/formatter.rb +9 -20
- data/lib/rbi/index.rb +49 -43
- data/lib/rbi/loc.rb +7 -19
- data/lib/rbi/model.rb +246 -584
- data/lib/rbi/parser.rb +227 -98
- data/lib/rbi/printer.rb +173 -108
- data/lib/rbi/rbs/method_type_translator.rb +120 -0
- data/lib/rbi/rbs/type_translator.rb +181 -0
- data/lib/rbi/rbs_printer.rb +273 -150
- data/lib/rbi/rewriters/add_sig_templates.rb +7 -10
- data/lib/rbi/rewriters/annotate.rb +6 -9
- data/lib/rbi/rewriters/attr_to_methods.rb +16 -32
- data/lib/rbi/rewriters/deannotate.rb +5 -8
- data/lib/rbi/rewriters/filter_versions.rb +7 -12
- data/lib/rbi/rewriters/flatten_singleton_methods.rb +5 -7
- data/lib/rbi/rewriters/flatten_visibilities.rb +6 -9
- data/lib/rbi/rewriters/group_nodes.rb +6 -11
- data/lib/rbi/rewriters/merge_trees.rb +84 -132
- data/lib/rbi/rewriters/nest_non_public_members.rb +5 -10
- data/lib/rbi/rewriters/nest_singleton_methods.rb +3 -6
- data/lib/rbi/rewriters/nest_top_level_members.rb +5 -8
- data/lib/rbi/rewriters/remove_known_definitions.rb +13 -23
- data/lib/rbi/rewriters/sort_nodes.rb +10 -11
- data/lib/rbi/rewriters/translate_rbs_sigs.rb +87 -0
- data/lib/rbi/type.rb +135 -137
- data/lib/rbi/type_parser.rb +51 -27
- data/lib/rbi/type_visitor.rb +19 -21
- data/lib/rbi/version.rb +1 -1
- data/lib/rbi/visitor.rb +55 -46
- data/lib/rbi.rb +7 -3
- data/rbi/rbi.rbi +3686 -0
- metadata +21 -7
data/lib/rbi/printer.rb
CHANGED
@@ -5,78 +5,70 @@ module RBI
|
|
5
5
|
class PrinterError < Error; end
|
6
6
|
|
7
7
|
class Printer < Visitor
|
8
|
-
|
9
|
-
|
10
|
-
sig { returns(T::Boolean) }
|
8
|
+
#: bool
|
11
9
|
attr_accessor :print_locs, :in_visibility_group
|
12
10
|
|
13
|
-
|
11
|
+
#: Node?
|
14
12
|
attr_reader :previous_node
|
15
13
|
|
16
|
-
|
14
|
+
#: Integer
|
17
15
|
attr_reader :current_indent
|
18
16
|
|
19
|
-
|
17
|
+
#: Integer?
|
20
18
|
attr_reader :max_line_length
|
21
19
|
|
22
|
-
|
23
|
-
params(
|
24
|
-
out: T.any(IO, StringIO),
|
25
|
-
indent: Integer,
|
26
|
-
print_locs: T::Boolean,
|
27
|
-
max_line_length: T.nilable(Integer),
|
28
|
-
).void
|
29
|
-
end
|
20
|
+
#: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void
|
30
21
|
def initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
|
31
22
|
super()
|
32
23
|
@out = out
|
33
24
|
@current_indent = indent
|
34
25
|
@print_locs = print_locs
|
35
|
-
@in_visibility_group =
|
36
|
-
@previous_node =
|
26
|
+
@in_visibility_group = false #: bool
|
27
|
+
@previous_node = nil #: Node?
|
37
28
|
@max_line_length = max_line_length
|
38
29
|
end
|
39
30
|
|
40
31
|
# Printing
|
41
32
|
|
42
|
-
|
33
|
+
#: -> void
|
43
34
|
def indent
|
44
35
|
@current_indent += 2
|
45
36
|
end
|
46
37
|
|
47
|
-
|
38
|
+
#: -> void
|
48
39
|
def dedent
|
49
40
|
@current_indent -= 2
|
50
41
|
end
|
51
42
|
|
52
43
|
# Print a string without indentation nor `\n` at the end.
|
53
|
-
|
44
|
+
#: (String string) -> void
|
54
45
|
def print(string)
|
55
46
|
@out.print(string)
|
56
47
|
end
|
57
48
|
|
58
49
|
# Print a string without indentation but with a `\n` at the end.
|
59
|
-
|
50
|
+
#: (?String? string) -> void
|
60
51
|
def printn(string = nil)
|
61
52
|
print(string) if string
|
62
53
|
print("\n")
|
63
54
|
end
|
64
55
|
|
65
56
|
# Print a string with indentation but without a `\n` at the end.
|
66
|
-
|
57
|
+
#: (?String? string) -> void
|
67
58
|
def printt(string = nil)
|
68
59
|
print(" " * @current_indent)
|
69
60
|
print(string) if string
|
70
61
|
end
|
71
62
|
|
72
63
|
# Print a string with indentation and `\n` at the end.
|
73
|
-
|
64
|
+
#: (String string) -> void
|
74
65
|
def printl(string)
|
75
66
|
printt
|
76
67
|
printn(string)
|
77
68
|
end
|
78
69
|
|
79
|
-
|
70
|
+
# @override
|
71
|
+
#: (Array[Node] nodes) -> void
|
80
72
|
def visit_all(nodes)
|
81
73
|
previous_node = @previous_node
|
82
74
|
@previous_node = nil
|
@@ -87,7 +79,8 @@ module RBI
|
|
87
79
|
@previous_node = previous_node
|
88
80
|
end
|
89
81
|
|
90
|
-
|
82
|
+
# @override
|
83
|
+
#: (File file) -> void
|
91
84
|
def visit_file(file)
|
92
85
|
strictness = file.strictness
|
93
86
|
if strictness
|
@@ -106,7 +99,25 @@ module RBI
|
|
106
99
|
|
107
100
|
private
|
108
101
|
|
109
|
-
|
102
|
+
# @override
|
103
|
+
#: (RBSComment node) -> void
|
104
|
+
def visit_rbs_comment(node)
|
105
|
+
lines = node.text.lines
|
106
|
+
|
107
|
+
if lines.empty?
|
108
|
+
printl("#:")
|
109
|
+
end
|
110
|
+
|
111
|
+
lines.each do |line|
|
112
|
+
text = line.rstrip
|
113
|
+
printt("#:")
|
114
|
+
print(" #{text}") unless text.empty?
|
115
|
+
printn
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# @override
|
120
|
+
#: (Comment node) -> void
|
110
121
|
def visit_comment(node)
|
111
122
|
lines = node.text.lines
|
112
123
|
|
@@ -122,39 +133,45 @@ module RBI
|
|
122
133
|
end
|
123
134
|
end
|
124
135
|
|
125
|
-
|
136
|
+
# @override
|
137
|
+
#: (BlankLine node) -> void
|
126
138
|
def visit_blank_line(node)
|
127
139
|
printn
|
128
140
|
end
|
129
141
|
|
130
|
-
|
142
|
+
# @override
|
143
|
+
#: (Tree node) -> void
|
131
144
|
def visit_tree(node)
|
132
145
|
visit_all(node.comments)
|
133
146
|
printn if !node.comments.empty? && !node.empty?
|
134
147
|
visit_all(node.nodes)
|
135
148
|
end
|
136
149
|
|
137
|
-
|
150
|
+
# @override
|
151
|
+
#: (Module node) -> void
|
138
152
|
def visit_module(node)
|
139
153
|
visit_scope(node)
|
140
154
|
end
|
141
155
|
|
142
|
-
|
156
|
+
# @override
|
157
|
+
#: (Class node) -> void
|
143
158
|
def visit_class(node)
|
144
159
|
visit_scope(node)
|
145
160
|
end
|
146
161
|
|
147
|
-
|
162
|
+
# @override
|
163
|
+
#: (Struct node) -> void
|
148
164
|
def visit_struct(node)
|
149
165
|
visit_scope(node)
|
150
166
|
end
|
151
167
|
|
152
|
-
|
168
|
+
# @override
|
169
|
+
#: (SingletonClass node) -> void
|
153
170
|
def visit_singleton_class(node)
|
154
171
|
visit_scope(node)
|
155
172
|
end
|
156
173
|
|
157
|
-
|
174
|
+
#: (Scope node) -> void
|
158
175
|
def visit_scope(node)
|
159
176
|
print_blank_line_before(node)
|
160
177
|
print_loc(node)
|
@@ -164,7 +181,7 @@ module RBI
|
|
164
181
|
visit_scope_body(node)
|
165
182
|
end
|
166
183
|
|
167
|
-
|
184
|
+
#: (Scope node) -> void
|
168
185
|
def visit_scope_header(node)
|
169
186
|
case node
|
170
187
|
when Module
|
@@ -199,7 +216,7 @@ module RBI
|
|
199
216
|
printn
|
200
217
|
end
|
201
218
|
|
202
|
-
|
219
|
+
#: (Scope node) -> void
|
203
220
|
def visit_scope_body(node)
|
204
221
|
return if node.empty?
|
205
222
|
|
@@ -209,7 +226,8 @@ module RBI
|
|
209
226
|
printl("end")
|
210
227
|
end
|
211
228
|
|
212
|
-
|
229
|
+
# @override
|
230
|
+
#: (Const node) -> void
|
213
231
|
def visit_const(node)
|
214
232
|
print_blank_line_before(node)
|
215
233
|
print_loc(node)
|
@@ -218,22 +236,25 @@ module RBI
|
|
218
236
|
printl("#{node.name} = #{node.value}")
|
219
237
|
end
|
220
238
|
|
221
|
-
|
239
|
+
# @override
|
240
|
+
#: (AttrAccessor node) -> void
|
222
241
|
def visit_attr_accessor(node)
|
223
242
|
visit_attr(node)
|
224
243
|
end
|
225
244
|
|
226
|
-
|
245
|
+
# @override
|
246
|
+
#: (AttrReader node) -> void
|
227
247
|
def visit_attr_reader(node)
|
228
248
|
visit_attr(node)
|
229
249
|
end
|
230
250
|
|
231
|
-
|
251
|
+
# @override
|
252
|
+
#: (AttrWriter node) -> void
|
232
253
|
def visit_attr_writer(node)
|
233
254
|
visit_attr(node)
|
234
255
|
end
|
235
256
|
|
236
|
-
|
257
|
+
#: (Attr node) -> void
|
237
258
|
def visit_attr(node)
|
238
259
|
print_blank_line_before(node)
|
239
260
|
|
@@ -261,7 +282,8 @@ module RBI
|
|
261
282
|
printn
|
262
283
|
end
|
263
284
|
|
264
|
-
|
285
|
+
# @override
|
286
|
+
#: (Method node) -> void
|
265
287
|
def visit_method(node)
|
266
288
|
print_blank_line_before(node)
|
267
289
|
visit_all(node.comments)
|
@@ -310,52 +332,61 @@ module RBI
|
|
310
332
|
printn
|
311
333
|
end
|
312
334
|
|
313
|
-
|
335
|
+
# @override
|
336
|
+
#: (ReqParam node) -> void
|
314
337
|
def visit_req_param(node)
|
315
338
|
print(node.name)
|
316
339
|
end
|
317
340
|
|
318
|
-
|
341
|
+
# @override
|
342
|
+
#: (OptParam node) -> void
|
319
343
|
def visit_opt_param(node)
|
320
344
|
print("#{node.name} = #{node.value}")
|
321
345
|
end
|
322
346
|
|
323
|
-
|
347
|
+
# @override
|
348
|
+
#: (RestParam node) -> void
|
324
349
|
def visit_rest_param(node)
|
325
350
|
print("*#{node.name}")
|
326
351
|
end
|
327
352
|
|
328
|
-
|
353
|
+
# @override
|
354
|
+
#: (KwParam node) -> void
|
329
355
|
def visit_kw_param(node)
|
330
356
|
print("#{node.name}:")
|
331
357
|
end
|
332
358
|
|
333
|
-
|
359
|
+
# @override
|
360
|
+
#: (KwOptParam node) -> void
|
334
361
|
def visit_kw_opt_param(node)
|
335
362
|
print("#{node.name}: #{node.value}")
|
336
363
|
end
|
337
364
|
|
338
|
-
|
365
|
+
# @override
|
366
|
+
#: (KwRestParam node) -> void
|
339
367
|
def visit_kw_rest_param(node)
|
340
368
|
print("**#{node.name}")
|
341
369
|
end
|
342
370
|
|
343
|
-
|
371
|
+
# @override
|
372
|
+
#: (BlockParam node) -> void
|
344
373
|
def visit_block_param(node)
|
345
374
|
print("&#{node.name}")
|
346
375
|
end
|
347
376
|
|
348
|
-
|
377
|
+
# @override
|
378
|
+
#: (Include node) -> void
|
349
379
|
def visit_include(node)
|
350
380
|
visit_mixin(node)
|
351
381
|
end
|
352
382
|
|
353
|
-
|
383
|
+
# @override
|
384
|
+
#: (Extend node) -> void
|
354
385
|
def visit_extend(node)
|
355
386
|
visit_mixin(node)
|
356
387
|
end
|
357
388
|
|
358
|
-
|
389
|
+
#: (Mixin node) -> void
|
359
390
|
def visit_mixin(node)
|
360
391
|
print_blank_line_before(node)
|
361
392
|
print_loc(node)
|
@@ -372,22 +403,25 @@ module RBI
|
|
372
403
|
printn(" #{node.names.join(", ")}")
|
373
404
|
end
|
374
405
|
|
375
|
-
|
406
|
+
# @override
|
407
|
+
#: (Public node) -> void
|
376
408
|
def visit_public(node)
|
377
409
|
visit_visibility(node)
|
378
410
|
end
|
379
411
|
|
380
|
-
|
412
|
+
# @override
|
413
|
+
#: (Protected node) -> void
|
381
414
|
def visit_protected(node)
|
382
415
|
visit_visibility(node)
|
383
416
|
end
|
384
417
|
|
385
|
-
|
418
|
+
# @override
|
419
|
+
#: (Private node) -> void
|
386
420
|
def visit_private(node)
|
387
421
|
visit_visibility(node)
|
388
422
|
end
|
389
423
|
|
390
|
-
|
424
|
+
#: (Visibility node) -> void
|
391
425
|
def visit_visibility(node)
|
392
426
|
print_blank_line_before(node)
|
393
427
|
print_loc(node)
|
@@ -396,7 +430,8 @@ module RBI
|
|
396
430
|
printl(node.visibility.to_s)
|
397
431
|
end
|
398
432
|
|
399
|
-
|
433
|
+
# @override
|
434
|
+
#: (Send node) -> void
|
400
435
|
def visit_send(node)
|
401
436
|
print_blank_line_before(node)
|
402
437
|
print_loc(node)
|
@@ -413,17 +448,20 @@ module RBI
|
|
413
448
|
printn
|
414
449
|
end
|
415
450
|
|
416
|
-
|
451
|
+
# @override
|
452
|
+
#: (Arg node) -> void
|
417
453
|
def visit_arg(node)
|
418
454
|
print(node.value)
|
419
455
|
end
|
420
456
|
|
421
|
-
|
457
|
+
# @override
|
458
|
+
#: (KwArg node) -> void
|
422
459
|
def visit_kw_arg(node)
|
423
460
|
print("#{node.keyword}: #{node.value}")
|
424
461
|
end
|
425
462
|
|
426
|
-
|
463
|
+
# @override
|
464
|
+
#: (Sig node) -> void
|
427
465
|
def visit_sig(node)
|
428
466
|
print_loc(node)
|
429
467
|
visit_all(node.comments)
|
@@ -443,27 +481,31 @@ module RBI
|
|
443
481
|
end
|
444
482
|
end
|
445
483
|
|
446
|
-
|
484
|
+
# @override
|
485
|
+
#: (SigParam node) -> void
|
447
486
|
def visit_sig_param(node)
|
448
487
|
print("#{node.name}: #{node.type}")
|
449
488
|
end
|
450
489
|
|
451
|
-
|
490
|
+
# @override
|
491
|
+
#: (TStruct node) -> void
|
452
492
|
def visit_tstruct(node)
|
453
493
|
visit_scope(node)
|
454
494
|
end
|
455
495
|
|
456
|
-
|
496
|
+
# @override
|
497
|
+
#: (TStructConst node) -> void
|
457
498
|
def visit_tstruct_const(node)
|
458
499
|
visit_t_struct_field(node)
|
459
500
|
end
|
460
501
|
|
461
|
-
|
502
|
+
# @override
|
503
|
+
#: (TStructProp node) -> void
|
462
504
|
def visit_tstruct_prop(node)
|
463
505
|
visit_t_struct_field(node)
|
464
506
|
end
|
465
507
|
|
466
|
-
|
508
|
+
#: (TStructField node) -> void
|
467
509
|
def visit_t_struct_field(node)
|
468
510
|
print_blank_line_before(node)
|
469
511
|
print_loc(node)
|
@@ -481,12 +523,14 @@ module RBI
|
|
481
523
|
printn
|
482
524
|
end
|
483
525
|
|
484
|
-
|
526
|
+
# @override
|
527
|
+
#: (TEnum node) -> void
|
485
528
|
def visit_tenum(node)
|
486
529
|
visit_scope(node)
|
487
530
|
end
|
488
531
|
|
489
|
-
|
532
|
+
# @override
|
533
|
+
#: (TEnumBlock node) -> void
|
490
534
|
def visit_tenum_block(node)
|
491
535
|
print_loc(node)
|
492
536
|
visit_all(node.comments)
|
@@ -498,7 +542,18 @@ module RBI
|
|
498
542
|
printl("end")
|
499
543
|
end
|
500
544
|
|
501
|
-
|
545
|
+
# @override
|
546
|
+
#: (TEnumValue node) -> void
|
547
|
+
def visit_tenum_value(node)
|
548
|
+
print_blank_line_before(node)
|
549
|
+
print_loc(node)
|
550
|
+
visit_all(node.comments)
|
551
|
+
|
552
|
+
printl("#{node.name} = new")
|
553
|
+
end
|
554
|
+
|
555
|
+
# @override
|
556
|
+
#: (TypeMember node) -> void
|
502
557
|
def visit_type_member(node)
|
503
558
|
print_blank_line_before(node)
|
504
559
|
print_loc(node)
|
@@ -507,7 +562,8 @@ module RBI
|
|
507
562
|
printl("#{node.name} = #{node.value}")
|
508
563
|
end
|
509
564
|
|
510
|
-
|
565
|
+
# @override
|
566
|
+
#: (Helper node) -> void
|
511
567
|
def visit_helper(node)
|
512
568
|
print_blank_line_before(node)
|
513
569
|
print_loc(node)
|
@@ -516,18 +572,21 @@ module RBI
|
|
516
572
|
printl("#{node.name}!")
|
517
573
|
end
|
518
574
|
|
519
|
-
|
575
|
+
# @override
|
576
|
+
#: (MixesInClassMethods node) -> void
|
520
577
|
def visit_mixes_in_class_methods(node)
|
521
578
|
visit_mixin(node)
|
522
579
|
end
|
523
580
|
|
524
|
-
|
581
|
+
# @override
|
582
|
+
#: (Group node) -> void
|
525
583
|
def visit_group(node)
|
526
584
|
printn unless previous_node.nil?
|
527
585
|
visit_all(node.nodes)
|
528
586
|
end
|
529
587
|
|
530
|
-
|
588
|
+
# @override
|
589
|
+
#: (VisibilityGroup node) -> void
|
531
590
|
def visit_visibility_group(node)
|
532
591
|
self.in_visibility_group = true
|
533
592
|
if node.visibility.public?
|
@@ -540,7 +599,8 @@ module RBI
|
|
540
599
|
self.in_visibility_group = false
|
541
600
|
end
|
542
601
|
|
543
|
-
|
602
|
+
# @override
|
603
|
+
#: (RequiresAncestor node) -> void
|
544
604
|
def visit_requires_ancestor(node)
|
545
605
|
print_blank_line_before(node)
|
546
606
|
print_loc(node)
|
@@ -549,7 +609,8 @@ module RBI
|
|
549
609
|
printl("requires_ancestor { #{node.name} }")
|
550
610
|
end
|
551
611
|
|
552
|
-
|
612
|
+
# @override
|
613
|
+
#: (ConflictTree node) -> void
|
553
614
|
def visit_conflict_tree(node)
|
554
615
|
printl("<<<<<<< #{node.left_name}")
|
555
616
|
visit(node.left)
|
@@ -558,7 +619,8 @@ module RBI
|
|
558
619
|
printl(">>>>>>> #{node.right_name}")
|
559
620
|
end
|
560
621
|
|
561
|
-
|
622
|
+
# @override
|
623
|
+
#: (ScopeConflict node) -> void
|
562
624
|
def visit_scope_conflict(node)
|
563
625
|
print_blank_line_before(node)
|
564
626
|
print_loc(node)
|
@@ -572,7 +634,7 @@ module RBI
|
|
572
634
|
visit_scope_body(node.left)
|
573
635
|
end
|
574
636
|
|
575
|
-
|
637
|
+
#: (Node node) -> void
|
576
638
|
def print_blank_line_before(node)
|
577
639
|
previous_node = self.previous_node
|
578
640
|
return unless previous_node
|
@@ -582,13 +644,13 @@ module RBI
|
|
582
644
|
printn
|
583
645
|
end
|
584
646
|
|
585
|
-
|
647
|
+
#: (Node node) -> void
|
586
648
|
def print_loc(node)
|
587
649
|
loc = node.loc
|
588
650
|
printl("# #{loc}") if loc && print_locs
|
589
651
|
end
|
590
652
|
|
591
|
-
|
653
|
+
#: (Param node, last: bool) -> void
|
592
654
|
def print_param_comment_leading_space(node, last:)
|
593
655
|
printn
|
594
656
|
printt
|
@@ -606,7 +668,7 @@ module RBI
|
|
606
668
|
end
|
607
669
|
end
|
608
670
|
|
609
|
-
|
671
|
+
#: (SigParam node, last: bool) -> void
|
610
672
|
def print_sig_param_comment_leading_space(node, last:)
|
611
673
|
printn
|
612
674
|
printt
|
@@ -614,7 +676,7 @@ module RBI
|
|
614
676
|
print(" ") unless last
|
615
677
|
end
|
616
678
|
|
617
|
-
|
679
|
+
#: (Node node) -> bool
|
618
680
|
def oneline?(node)
|
619
681
|
case node
|
620
682
|
when ScopeConflict
|
@@ -623,6 +685,13 @@ module RBI
|
|
623
685
|
node.comments.empty? && node.empty?
|
624
686
|
when Attr
|
625
687
|
node.comments.empty? && node.sigs.empty?
|
688
|
+
when Const
|
689
|
+
return false unless node.comments.empty?
|
690
|
+
|
691
|
+
loc = node.loc
|
692
|
+
return true unless loc
|
693
|
+
|
694
|
+
loc.begin_line == loc.end_line
|
626
695
|
when Method
|
627
696
|
node.comments.empty? && node.sigs.empty? && node.params.all? { |p| p.comments.empty? }
|
628
697
|
when Sig
|
@@ -636,9 +705,11 @@ module RBI
|
|
636
705
|
end
|
637
706
|
end
|
638
707
|
|
639
|
-
|
708
|
+
#: (Sig node) -> void
|
640
709
|
def print_sig_as_line(node)
|
641
|
-
printt
|
710
|
+
printt
|
711
|
+
print("T::Sig::WithoutRuntime.") if node.without_runtime
|
712
|
+
print("sig")
|
642
713
|
print("(:final)") if node.is_final
|
643
714
|
print(" { ")
|
644
715
|
sig_modifiers(node).each do |modifier|
|
@@ -661,16 +732,20 @@ module RBI
|
|
661
732
|
printn(" }")
|
662
733
|
end
|
663
734
|
|
664
|
-
|
735
|
+
#: (Sig node) -> void
|
665
736
|
def print_sig_as_block(node)
|
666
737
|
modifiers = sig_modifiers(node)
|
667
738
|
|
668
|
-
printt
|
739
|
+
printt
|
740
|
+
print("T::Sig::WithoutRuntime.") if node.without_runtime
|
741
|
+
print("sig")
|
669
742
|
print("(:final)") if node.is_final
|
670
743
|
printn(" do")
|
671
744
|
indent
|
672
745
|
if modifiers.any?
|
673
|
-
printl(
|
746
|
+
printl(
|
747
|
+
modifiers.first, #: as !nil
|
748
|
+
)
|
674
749
|
indent
|
675
750
|
modifiers[1..]&.each do |modifier|
|
676
751
|
printl(".#{modifier}")
|
@@ -717,11 +792,19 @@ module RBI
|
|
717
792
|
printl("end")
|
718
793
|
end
|
719
794
|
|
720
|
-
|
795
|
+
#: (Sig node) -> Array[String]
|
721
796
|
def sig_modifiers(node)
|
722
|
-
modifiers =
|
797
|
+
modifiers = [] #: Array[String]
|
723
798
|
modifiers << "abstract" if node.is_abstract
|
724
|
-
|
799
|
+
|
800
|
+
if node.is_override
|
801
|
+
modifiers << if node.allow_incompatible_override
|
802
|
+
"override(allow_incompatible: true)"
|
803
|
+
else
|
804
|
+
"override"
|
805
|
+
end
|
806
|
+
end
|
807
|
+
|
725
808
|
modifiers << "overridable" if node.is_overridable
|
726
809
|
modifiers << "type_parameters(#{node.type_params.map { |type| ":#{type}" }.join(", ")})" if node.type_params.any?
|
727
810
|
modifiers << "checked(:#{node.checked})" if node.checked
|
@@ -730,22 +813,13 @@ module RBI
|
|
730
813
|
end
|
731
814
|
|
732
815
|
class File
|
733
|
-
|
734
|
-
|
735
|
-
sig do
|
736
|
-
params(
|
737
|
-
out: T.any(IO, StringIO),
|
738
|
-
indent: Integer,
|
739
|
-
print_locs: T::Boolean,
|
740
|
-
max_line_length: T.nilable(Integer),
|
741
|
-
).void
|
742
|
-
end
|
816
|
+
#: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void
|
743
817
|
def print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
|
744
818
|
p = Printer.new(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length)
|
745
819
|
p.visit_file(self)
|
746
820
|
end
|
747
821
|
|
748
|
-
|
822
|
+
#: (?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> String
|
749
823
|
def string(indent: 0, print_locs: false, max_line_length: nil)
|
750
824
|
out = StringIO.new
|
751
825
|
print(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length)
|
@@ -754,22 +828,13 @@ module RBI
|
|
754
828
|
end
|
755
829
|
|
756
830
|
class Node
|
757
|
-
|
758
|
-
|
759
|
-
sig do
|
760
|
-
params(
|
761
|
-
out: T.any(IO, StringIO),
|
762
|
-
indent: Integer,
|
763
|
-
print_locs: T::Boolean,
|
764
|
-
max_line_length: T.nilable(Integer),
|
765
|
-
).void
|
766
|
-
end
|
831
|
+
#: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void
|
767
832
|
def print(out: $stdout, indent: 0, print_locs: false, max_line_length: nil)
|
768
833
|
p = Printer.new(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length)
|
769
834
|
p.visit(self)
|
770
835
|
end
|
771
836
|
|
772
|
-
|
837
|
+
#: (?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> String
|
773
838
|
def string(indent: 0, print_locs: false, max_line_length: nil)
|
774
839
|
out = StringIO.new
|
775
840
|
print(out: out, indent: indent, print_locs: print_locs, max_line_length: max_line_length)
|