rbs-inline 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c6ea86390a9ce51331956c34fb2eedc77ae45c4ac0fc7b39d67f2cacb2a5af0
4
- data.tar.gz: 9e1446ab0920edec03ed54a1a07c8868e3dac9529813c389ed35f85f0380e7c9
3
+ metadata.gz: 330c5c083c1dda38f3f0263729aea1d39c16484e67deee0717b28881ec22da8a
4
+ data.tar.gz: 2f1e8f2910669d33f6ed64897b0e5db00285b42626d846402a85c5c294c23155
5
5
  SHA512:
6
- metadata.gz: 793f9e99431ac027e1ccf6d3b2b31ead740b9227584aa5be5f751cd1eafea85ce8db37e070b5dfcde28139f629d2c2a499aa5e2d507fcbe53c7fd8a3e9cf2377
7
- data.tar.gz: 3f74d9a9a96189fcd21c470aa7b97949fa625dbb46b218c6ae993b049993947d7a27840755af43626702aa6b55cebc1a25d70830343c6f954bcb2694f30fc34b
6
+ metadata.gz: ad396cb989f857ada7203ca6ab2129dae79f471520d816e791c8be80b9d3d4b3d5301f8360dfe8ccba5fe30d99f92dd56eea81c32b092a946d91aab431f57e26
7
+ data.tar.gz: 4487616c28a042e68f167ea191b7ab4265704228b6a104e0bf52a15d909b096bb8a8798d273de97cebba72f2a8bf0b2635168cee5e7961a7c37ec0a9f3364c25
@@ -404,6 +404,12 @@ module RBS
404
404
  token[1]
405
405
  end
406
406
  end
407
+
408
+ def annotations #: Array[RBS::AST::Annotation]
409
+ contents.map do |content|
410
+ RBS::AST::Annotation.new(string: content[3..-2] || raise, location: nil)
411
+ end
412
+ end
407
413
  end
408
414
 
409
415
  # `# @rbs skip`
@@ -13,10 +13,22 @@ module RBS
13
13
  TypeName(node.full_name)
14
14
  end
15
15
  end
16
+
17
+ # @rbs (Prism::Node) -> Prism::Node?
18
+ def value_node(node)
19
+ case node
20
+ when Prism::ConstantWriteNode
21
+ value_node(node.value)
22
+ when Prism::LocalVariableWriteNode
23
+ value_node(node.value)
24
+ else
25
+ node
26
+ end
27
+ end
16
28
  end
17
29
 
18
30
  # @rbs!
19
- # type t = ClassDecl | ModuleDecl | ConstantDecl | SingletonClassDecl | BlockDecl
31
+ # type t = ClassDecl | ModuleDecl | ConstantDecl | SingletonClassDecl | BlockDecl | DataAssignDecl | StructAssignDecl
20
32
  #
21
33
  # interface _WithComments
22
34
  # def comments: () -> AnnotationParser::ParsingResult?
@@ -266,6 +278,231 @@ module RBS
266
278
  end
267
279
  end
268
280
  end
281
+
282
+ # @rbs module-self _WithTypeDecls
283
+ module DataStructUtil
284
+ # @rbs!
285
+ # interface _WithTypeDecls
286
+ # def type_decls: () -> Hash[Integer, Annotations::TypeAssertion]
287
+ #
288
+ # def each_attribute_argument: () { (Prism::Node) -> void } -> void
289
+ #
290
+ # def comments: %a{pure} () -> AnnotationParser::ParsingResult?
291
+ # end
292
+
293
+ # @rbs %a{pure}
294
+ # @rbs () { ([Symbol, Annotations::TypeAssertion?]) -> void } -> void
295
+ # | () -> Enumerator[[Symbol, Annotations::TypeAssertion?], void]
296
+ def each_attribute(&block)
297
+ if block
298
+ each_attribute_argument do |arg|
299
+ if arg.is_a?(Prism::SymbolNode)
300
+ if name = arg.value
301
+ type = type_decls.fetch(arg.location.start_line, nil)
302
+ yield [name.to_sym, type]
303
+ end
304
+ end
305
+ end
306
+ else
307
+ enum_for :each_attribute
308
+ end
309
+ end
310
+
311
+ def class_annotations #: Array[RBS::AST::Annotation]
312
+ annotations = [] #: Array[RBS::AST::Annotation]
313
+
314
+ comments&.each_annotation do |annotation|
315
+ if annotation.is_a?(Annotations::RBSAnnotation)
316
+ annotations.concat annotation.annotations
317
+ end
318
+ end
319
+
320
+ annotations
321
+ end
322
+ end
323
+
324
+ class DataAssignDecl < Base
325
+ extend ConstantUtil
326
+
327
+ include DataStructUtil
328
+
329
+ attr_reader :node #: Prism::ConstantWriteNode
330
+
331
+ attr_reader :comments #: AnnotationParser::ParsingResult?
332
+
333
+ attr_reader :type_decls #: Hash[Integer, Annotations::TypeAssertion]
334
+
335
+ attr_reader :data_define_node #: Prism::CallNode
336
+
337
+ # @rbs (Prism::ConstantWriteNode, Prism::CallNode, AnnotationParser::ParsingResult?, Hash[Integer, Annotations::TypeAssertion]) -> void
338
+ def initialize(node, data_define_node, comments, type_decls)
339
+ @node = node
340
+ @comments = comments
341
+ @type_decls = type_decls
342
+ @data_define_node = data_define_node
343
+ end
344
+
345
+ def start_line #: Integer
346
+ node.location.start_line
347
+ end
348
+
349
+ # @rbs %a{pure}
350
+ # @rbs () -> TypeName?
351
+ def constant_name
352
+ TypeName.new(name: node.name, namespace: Namespace.empty)
353
+ end
354
+
355
+ # @rbs (Prism::ConstantWriteNode) -> Prism::CallNode?
356
+ def self.data_define?(node)
357
+ value = value_node(node)
358
+
359
+ if value.is_a?(Prism::CallNode)
360
+ if value.receiver.is_a?(Prism::ConstantReadNode)
361
+ if value.receiver.full_name.delete_prefix("::") == "Data"
362
+ if value.name == :define
363
+ return value
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+
370
+ # @rbs () { (Prism::Node) -> void } -> void
371
+ def each_attribute_argument(&block)
372
+ if args = data_define_node.arguments
373
+ args.arguments.each(&block)
374
+ end
375
+ end
376
+ end
377
+
378
+ class StructAssignDecl < Base
379
+ extend ConstantUtil
380
+
381
+ include DataStructUtil
382
+
383
+ attr_reader :node #: Prism::ConstantWriteNode
384
+
385
+ attr_reader :comments #: AnnotationParser::ParsingResult?
386
+
387
+ attr_reader :type_decls #: Hash[Integer, Annotations::TypeAssertion]
388
+
389
+ attr_reader :struct_new_node #: Prism::CallNode
390
+
391
+ # @rbs (Prism::ConstantWriteNode, Prism::CallNode, AnnotationParser::ParsingResult?, Hash[Integer, Annotations::TypeAssertion]) -> void
392
+ def initialize(node, struct_new_node, comments, type_decls)
393
+ @node = node
394
+ @comments = comments
395
+ @type_decls = type_decls
396
+ @struct_new_node = struct_new_node
397
+ end
398
+
399
+ def start_line #: Integer
400
+ node.location.start_line
401
+ end
402
+
403
+ # @rbs %a{pure}
404
+ # @rbs () -> TypeName?
405
+ def constant_name
406
+ TypeName.new(name: node.name, namespace: Namespace.empty)
407
+ end
408
+
409
+ # @rbs () { (Prism::Node) -> void } -> void
410
+ def each_attribute_argument(&block)
411
+ if args = struct_new_node.arguments
412
+ args.arguments.each do |arg|
413
+ next if arg.is_a?(Prism::KeywordHashNode)
414
+ next if arg.is_a?(Prism::StringNode)
415
+
416
+ yield arg
417
+ end
418
+ end
419
+ end
420
+
421
+ # @rbs (Prism::ConstantWriteNode) -> Prism::CallNode?
422
+ def self.struct_new?(node)
423
+ value = value_node(node)
424
+
425
+ if value.is_a?(Prism::CallNode)
426
+ if value.receiver.is_a?(Prism::ConstantReadNode)
427
+ if value.receiver.full_name.delete_prefix("::") == "Struct"
428
+ if value.name == :new
429
+ return value
430
+ end
431
+ end
432
+ end
433
+ end
434
+ end
435
+
436
+ # @rbs %a{pure}
437
+ def keyword_init? #: bool
438
+ if args = struct_new_node.arguments
439
+ args.arguments.each do |arg|
440
+ if arg.is_a?(Prism::KeywordHashNode)
441
+ arg.elements.each do |assoc|
442
+ if assoc.is_a?(Prism::AssocNode)
443
+ if (key = assoc.key).is_a?(Prism::SymbolNode)
444
+ if key.value == "keyword_init"
445
+ value = assoc.value
446
+ if value.is_a?(Prism::FalseNode)
447
+ return false
448
+ end
449
+ end
450
+ end
451
+ end
452
+ end
453
+ end
454
+ end
455
+ end
456
+
457
+ true
458
+ end
459
+
460
+ # @rbs %a{pure}
461
+ def positional_init? #: bool
462
+ if args = struct_new_node.arguments
463
+ args.arguments.each do |arg|
464
+ if arg.is_a?(Prism::KeywordHashNode)
465
+ arg.elements.each do |assoc|
466
+ if assoc.is_a?(Prism::AssocNode)
467
+ if (key = assoc.key).is_a?(Prism::SymbolNode)
468
+ if key.value == "keyword_init"
469
+ value = assoc.value
470
+ if value.is_a?(Prism::TrueNode)
471
+ return false
472
+ end
473
+ end
474
+ end
475
+ end
476
+ end
477
+ end
478
+ end
479
+ end
480
+
481
+ true
482
+ end
483
+
484
+ # Returns `true` is annotation is given to make all attributes *readonly*
485
+ #
486
+ # Add `# @rbs %a{rbs-inline:readonly-attributes=true}` to the class to make all attributes `attr_reader`, instead of `attr_accessor`.
487
+ #
488
+ # @rbs %a{pure}
489
+ def readonly_attributes? #: bool
490
+ class_annotations.any? do |annotation|
491
+ annotation.string == "rbs-inline:readonly-attributes=true"
492
+ end
493
+ end
494
+
495
+ # Returns `true` if annotation is given to make all `.new` arguments required
496
+ #
497
+ # Add `# @rbs %a{rbs-inline:new-args=required}` to the class to make all of the parameters required.
498
+ #
499
+ # @rbs %a{pure}
500
+ def required_new_args? #: bool
501
+ class_annotations.any? do |annotation|
502
+ annotation.string == "rbs-inline:new-args=required"
503
+ end
504
+ end
505
+ end
269
506
  end
270
507
  end
271
508
  end
@@ -277,12 +277,7 @@ module RBS
277
277
  if comments
278
278
  comments.each_annotation.flat_map do |annotation|
279
279
  if annotation.is_a?(AST::Annotations::RBSAnnotation)
280
- annotation.contents.map do |string|
281
- RBS::AST::Annotation.new(
282
- string: string[3...-1] || "",
283
- location: nil
284
- )
285
- end
280
+ annotation.annotations
286
281
  else
287
282
  []
288
283
  end
@@ -417,9 +417,38 @@ module RBS
417
417
  return if ignored_node?(node)
418
418
 
419
419
  comment = comments.delete(node.location.start_line - 1)
420
- assertion = assertion_annotation(node)
421
420
 
422
- decl = AST::Declarations::ConstantDecl.new(node, comment, assertion)
421
+ case
422
+ when data_node = AST::Declarations::DataAssignDecl.data_define?(node)
423
+ type_decls = {} #: Hash[Integer, AST::Annotations::TypeAssertion]
424
+
425
+ inner_annotations(node.location.start_line, node.location.end_line).flat_map do |comment|
426
+ comment.each_annotation do |annotation|
427
+ if annotation.is_a?(AST::Annotations::TypeAssertion)
428
+ start_line = annotation.source.comments[0].location.start_line
429
+ type_decls[start_line] = annotation
430
+ end
431
+ end
432
+ end
433
+
434
+ decl = AST::Declarations::DataAssignDecl.new(node, data_node, comment, type_decls)
435
+ when struct_node = AST::Declarations::StructAssignDecl.struct_new?(node)
436
+ type_decls = {} #: Hash[Integer, AST::Annotations::TypeAssertion]
437
+
438
+ inner_annotations(node.location.start_line, node.location.end_line).flat_map do |comment|
439
+ comment.each_annotation do |annotation|
440
+ if annotation.is_a?(AST::Annotations::TypeAssertion)
441
+ start_line = annotation.source.comments[0].location.start_line
442
+ type_decls[start_line] = annotation
443
+ end
444
+ end
445
+ end
446
+
447
+ decl = AST::Declarations::StructAssignDecl.new(node, struct_node, comment, type_decls)
448
+ else
449
+ assertion = assertion_annotation(node)
450
+ decl = AST::Declarations::ConstantDecl.new(node, comment, assertion)
451
+ end
423
452
 
424
453
  if current = current_class_module_decl
425
454
  current.members << decl
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RBS
4
4
  module Inline
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -77,6 +77,10 @@ module RBS
77
77
  translate_module_decl(decl, rbs)
78
78
  when AST::Declarations::ConstantDecl
79
79
  translate_constant_decl(decl, rbs)
80
+ when AST::Declarations::DataAssignDecl
81
+ translate_data_assign_decl(decl, rbs)
82
+ when AST::Declarations::StructAssignDecl
83
+ translate_struct_assign_decl(decl, rbs)
80
84
  when AST::Declarations::BlockDecl
81
85
  if decl.module_class_annotation
82
86
  case decl.module_class_annotation
@@ -131,7 +135,7 @@ module RBS
131
135
  else
132
136
  translate_members(member.members, decl, rbs)
133
137
  end
134
- when AST::Declarations::ClassDecl, AST::Declarations::ModuleDecl, AST::Declarations::ConstantDecl
138
+ when AST::Declarations::ClassDecl, AST::Declarations::ModuleDecl, AST::Declarations::ConstantDecl, AST::Declarations::DataAssignDecl, AST::Declarations::StructAssignDecl
135
139
  translate_decl(member, rbs)
136
140
  end
137
141
  end
@@ -182,6 +186,202 @@ module RBS
182
186
  )
183
187
  end
184
188
 
189
+ # @rbs decl: AST::Declarations::DataAssignDecl
190
+ # @rbs rbs: _Content
191
+ def translate_data_assign_decl(decl, rbs) #: void
192
+ return unless decl.constant_name
193
+
194
+ if decl.comments
195
+ comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
196
+ end
197
+
198
+ attributes = decl.each_attribute.map do |name, type|
199
+ RBS::AST::Members::AttrReader.new(
200
+ name: name,
201
+ type: type&.type || Types::Bases::Any.new(location: nil),
202
+ ivar_name: false,
203
+ comment: nil,
204
+ kind: :instance,
205
+ annotations: [],
206
+ visibility: nil,
207
+ location: nil
208
+ )
209
+ end
210
+
211
+ new = RBS::AST::Members::MethodDefinition.new(
212
+ name: :new,
213
+ kind: :singleton,
214
+ overloads: [
215
+ RBS::AST::Members::MethodDefinition::Overload.new(
216
+ method_type: RBS::MethodType.new(
217
+ type_params: [],
218
+ type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
219
+ required_positionals: decl.each_attribute.map do |name, attr|
220
+ RBS::Types::Function::Param.new(
221
+ type: attr&.type || Types::Bases::Any.new(location: nil),
222
+ name: name,
223
+ location: nil
224
+ )
225
+ end
226
+ ),
227
+ block: nil,
228
+ location: nil
229
+ ),
230
+ annotations: []
231
+ ),
232
+ RBS::AST::Members::MethodDefinition::Overload.new(
233
+ method_type: RBS::MethodType.new(
234
+ type_params: [],
235
+ type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
236
+ required_keywords: decl.each_attribute.map do |name, attr|
237
+ [
238
+ name,
239
+ RBS::Types::Function::Param.new(
240
+ type: attr&.type || Types::Bases::Any.new(location: nil),
241
+ name: nil,
242
+ location: nil
243
+ )
244
+ ]
245
+ end.to_h
246
+ ),
247
+ block: nil,
248
+ location: nil
249
+ ),
250
+ annotations: []
251
+ )
252
+ ],
253
+ annotations: [],
254
+ location: nil,
255
+ comment: nil,
256
+ overloading: false,
257
+ visibility: nil
258
+ )
259
+
260
+ rbs << RBS::AST::Declarations::Class.new(
261
+ name: decl.constant_name,
262
+ type_params: [],
263
+ members: [*attributes, new],
264
+ super_class: RBS::AST::Declarations::Class::Super.new(
265
+ name: RBS::TypeName.new(name: :Data, namespace: RBS::Namespace.empty),
266
+ args: [],
267
+ location: nil
268
+ ),
269
+ annotations: decl.class_annotations,
270
+ location: nil,
271
+ comment: comment
272
+ )
273
+ end
274
+
275
+ # @rbs decl: AST::Declarations::StructAssignDecl
276
+ # @rbs rbs: _Content
277
+ def translate_struct_assign_decl(decl, rbs) #: void
278
+ return unless decl.constant_name
279
+
280
+ if decl.comments
281
+ comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
282
+ end
283
+
284
+ attributes = decl.each_attribute.map do |name, type|
285
+ if decl.readonly_attributes?
286
+ RBS::AST::Members::AttrReader.new(
287
+ name: name,
288
+ type: type&.type || Types::Bases::Any.new(location: nil),
289
+ ivar_name: false,
290
+ comment: nil,
291
+ kind: :instance,
292
+ annotations: [],
293
+ visibility: nil,
294
+ location: nil
295
+ )
296
+ else
297
+ RBS::AST::Members::AttrAccessor.new(
298
+ name: name,
299
+ type: type&.type || Types::Bases::Any.new(location: nil),
300
+ ivar_name: false,
301
+ comment: nil,
302
+ kind: :instance,
303
+ annotations: [],
304
+ visibility: nil,
305
+ location: nil
306
+ )
307
+ end
308
+ end
309
+
310
+ new = RBS::AST::Members::MethodDefinition.new(
311
+ name: :new,
312
+ kind: :singleton,
313
+ overloads: [],
314
+ annotations: [],
315
+ location: nil,
316
+ comment: nil,
317
+ overloading: false,
318
+ visibility: nil
319
+ )
320
+
321
+ if decl.positional_init?
322
+ attr_params = decl.each_attribute.map do |name, attr|
323
+ RBS::Types::Function::Param.new(
324
+ type: attr&.type || Types::Bases::Any.new(location: nil),
325
+ name: name,
326
+ location: nil
327
+ )
328
+ end
329
+
330
+ method_type = Types::Function.empty(Types::Bases::Instance.new(location: nil))
331
+ if decl.required_new_args?
332
+ method_type = method_type.update(required_positionals: attr_params)
333
+ else
334
+ method_type = method_type.update(optional_positionals: attr_params)
335
+ end
336
+
337
+ new.overloads <<
338
+ RBS::AST::Members::MethodDefinition::Overload.new(
339
+ method_type: RBS::MethodType.new(type_params: [], type: method_type, block: nil, location: nil),
340
+ annotations: []
341
+ )
342
+ end
343
+
344
+ if decl.keyword_init?
345
+ attr_keywords = decl.each_attribute.map do |name, attr|
346
+ [
347
+ name,
348
+ RBS::Types::Function::Param.new(
349
+ type: attr&.type || Types::Bases::Any.new(location: nil),
350
+ name: nil,
351
+ location: nil
352
+ )
353
+ ]
354
+ end.to_h #: Hash[Symbol, RBS::Types::Function::Param]
355
+
356
+ method_type = Types::Function.empty(Types::Bases::Instance.new(location: nil))
357
+ if decl.required_new_args?
358
+ method_type = method_type.update(required_keywords: attr_keywords)
359
+ else
360
+ method_type = method_type.update(optional_keywords: attr_keywords)
361
+ end
362
+
363
+ new.overloads <<
364
+ RBS::AST::Members::MethodDefinition::Overload.new(
365
+ method_type: RBS::MethodType.new(type_params: [], type: method_type, block: nil, location: nil),
366
+ annotations: []
367
+ )
368
+ end
369
+
370
+ rbs << RBS::AST::Declarations::Class.new(
371
+ name: decl.constant_name,
372
+ type_params: [],
373
+ members: [*attributes, new],
374
+ super_class: RBS::AST::Declarations::Class::Super.new(
375
+ name: RBS::TypeName.new(name: :Struct, namespace: RBS::Namespace.empty),
376
+ args: [RBS::Types::Bases::Any.new(location: nil)],
377
+ location: nil
378
+ ),
379
+ annotations: decl.class_annotations,
380
+ location: nil,
381
+ comment: comment
382
+ )
383
+ end
384
+
185
385
  # @rbs decl: AST::Declarations::SingletonClassDecl
186
386
  # @rbs rbs: _Content
187
387
  # @rbs return: void
@@ -42,11 +42,11 @@ gems:
42
42
  source:
43
43
  type: git
44
44
  name: ruby/gem_rbs_collection
45
- revision: 4bf1c9687fc24cfbb30f4759653308c816f3a69f
45
+ revision: 3670834268f4ea9c10aefeffae7e072b51256375
46
46
  remote: https://github.com/ruby/gem_rbs_collection.git
47
47
  repo_dir: gems
48
48
  - name: rbs
49
- version: 3.5.1
49
+ version: 3.5.2
50
50
  source:
51
51
  type: rubygems
52
52
  - name: rdoc
@@ -157,6 +157,8 @@ module RBS
157
157
 
158
158
  # @rbs override
159
159
  def initialize: ...
160
+
161
+ def annotations: () -> Array[RBS::AST::Annotation]
160
162
  end
161
163
 
162
164
  # `# @rbs skip`
@@ -8,9 +8,12 @@ module RBS
8
8
  # @rbs node: Prism::Node
9
9
  # @rbs return: TypeName?
10
10
  def type_name: (Prism::Node node) -> TypeName?
11
+
12
+ # @rbs (Prism::Node) -> Prism::Node?
13
+ def value_node: (Prism::Node) -> Prism::Node?
11
14
  end
12
15
 
13
- type t = ClassDecl | ModuleDecl | ConstantDecl | SingletonClassDecl | BlockDecl
16
+ type t = ClassDecl | ModuleDecl | ConstantDecl | SingletonClassDecl | BlockDecl | DataAssignDecl | StructAssignDecl
14
17
 
15
18
  interface _WithComments
16
19
  def comments: () -> AnnotationParser::ParsingResult?
@@ -129,6 +132,110 @@ module RBS
129
132
 
130
133
  def module_class_annotation: () -> (Annotations::ModuleDecl | Annotations::ClassDecl | nil)
131
134
  end
135
+
136
+ # @rbs module-self _WithTypeDecls
137
+ module DataStructUtil : _WithTypeDecls
138
+ interface _WithTypeDecls
139
+ def type_decls: () -> Hash[Integer, Annotations::TypeAssertion]
140
+
141
+ def each_attribute_argument: () { (Prism::Node) -> void } -> void
142
+
143
+ def comments: %a{pure} () -> AnnotationParser::ParsingResult?
144
+ end
145
+
146
+ # @rbs %a{pure}
147
+ # @rbs () { ([Symbol, Annotations::TypeAssertion?]) -> void } -> void
148
+ # | () -> Enumerator[[Symbol, Annotations::TypeAssertion?], void]
149
+ %a{pure}
150
+ def each_attribute: () { ([ Symbol, Annotations::TypeAssertion? ]) -> void } -> void
151
+ | () -> Enumerator[[ Symbol, Annotations::TypeAssertion? ], void]
152
+
153
+ def class_annotations: () -> Array[RBS::AST::Annotation]
154
+ end
155
+
156
+ class DataAssignDecl < Base
157
+ extend ConstantUtil
158
+
159
+ include DataStructUtil
160
+
161
+ attr_reader node: Prism::ConstantWriteNode
162
+
163
+ attr_reader comments: AnnotationParser::ParsingResult?
164
+
165
+ attr_reader type_decls: Hash[Integer, Annotations::TypeAssertion]
166
+
167
+ attr_reader data_define_node: Prism::CallNode
168
+
169
+ # @rbs (Prism::ConstantWriteNode, Prism::CallNode, AnnotationParser::ParsingResult?, Hash[Integer, Annotations::TypeAssertion]) -> void
170
+ def initialize: (Prism::ConstantWriteNode, Prism::CallNode, AnnotationParser::ParsingResult?, Hash[Integer, Annotations::TypeAssertion]) -> void
171
+
172
+ def start_line: () -> Integer
173
+
174
+ # @rbs %a{pure}
175
+ # @rbs () -> TypeName?
176
+ %a{pure}
177
+ def constant_name: () -> TypeName?
178
+
179
+ # @rbs (Prism::ConstantWriteNode) -> Prism::CallNode?
180
+ def self.data_define?: (Prism::ConstantWriteNode) -> Prism::CallNode?
181
+
182
+ # @rbs () { (Prism::Node) -> void } -> void
183
+ def each_attribute_argument: () { (Prism::Node) -> void } -> void
184
+ end
185
+
186
+ class StructAssignDecl < Base
187
+ extend ConstantUtil
188
+
189
+ include DataStructUtil
190
+
191
+ attr_reader node: Prism::ConstantWriteNode
192
+
193
+ attr_reader comments: AnnotationParser::ParsingResult?
194
+
195
+ attr_reader type_decls: Hash[Integer, Annotations::TypeAssertion]
196
+
197
+ attr_reader struct_new_node: Prism::CallNode
198
+
199
+ # @rbs (Prism::ConstantWriteNode, Prism::CallNode, AnnotationParser::ParsingResult?, Hash[Integer, Annotations::TypeAssertion]) -> void
200
+ def initialize: (Prism::ConstantWriteNode, Prism::CallNode, AnnotationParser::ParsingResult?, Hash[Integer, Annotations::TypeAssertion]) -> void
201
+
202
+ def start_line: () -> Integer
203
+
204
+ # @rbs %a{pure}
205
+ # @rbs () -> TypeName?
206
+ %a{pure}
207
+ def constant_name: () -> TypeName?
208
+
209
+ # @rbs () { (Prism::Node) -> void } -> void
210
+ def each_attribute_argument: () { (Prism::Node) -> void } -> void
211
+
212
+ # @rbs (Prism::ConstantWriteNode) -> Prism::CallNode?
213
+ def self.struct_new?: (Prism::ConstantWriteNode) -> Prism::CallNode?
214
+
215
+ # @rbs %a{pure}
216
+ %a{pure}
217
+ def keyword_init?: () -> bool
218
+
219
+ # @rbs %a{pure}
220
+ %a{pure}
221
+ def positional_init?: () -> bool
222
+
223
+ # Returns `true` is annotation is given to make all attributes *readonly*
224
+ #
225
+ # Add `# @rbs %a{rbs-inline:readonly-attributes=true}` to the class to make all attributes `attr_reader`, instead of `attr_accessor`.
226
+ #
227
+ # @rbs %a{pure}
228
+ %a{pure}
229
+ def readonly_attributes?: () -> bool
230
+
231
+ # Returns `true` if annotation is given to make all `.new` arguments required
232
+ #
233
+ # Add `# @rbs %a{rbs-inline:new-args=required}` to the class to make all of the parameters required.
234
+ #
235
+ # @rbs %a{pure}
236
+ %a{pure}
237
+ def required_new_args?: () -> bool
238
+ end
132
239
  end
133
240
  end
134
241
  end
@@ -58,6 +58,14 @@ module RBS
58
58
  # @rbs return: void
59
59
  def translate_constant_decl: (AST::Declarations::ConstantDecl decl, _Content rbs) -> void
60
60
 
61
+ # @rbs decl: AST::Declarations::DataAssignDecl
62
+ # @rbs rbs: _Content
63
+ def translate_data_assign_decl: (AST::Declarations::DataAssignDecl decl, _Content rbs) -> void
64
+
65
+ # @rbs decl: AST::Declarations::StructAssignDecl
66
+ # @rbs rbs: _Content
67
+ def translate_struct_assign_decl: (AST::Declarations::StructAssignDecl decl, _Content rbs) -> void
68
+
61
69
  # @rbs decl: AST::Declarations::SingletonClassDecl
62
70
  # @rbs rbs: _Content
63
71
  # @rbs return: void
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-01 00:00:00.000000000 Z
11
+ date: 2024-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prism
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.5.3
113
+ rubygems_version: 3.5.11
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Inline RBS type declaration.