@@ -14,6 +14,77 @@ def initialize(buffer)
1414 include Helpers ::LocationHelper
1515 end
1616
17+ class MethodTypeAnnotation
18+ attr_reader :type_annotations
19+
20+ def initialize ( type_annotations :)
21+ @type_annotations = type_annotations
22+ end
23+
24+ def map_type_name ( &block )
25+ case type_annotations
26+ when Array
27+ updated_annots = type_annotations . map do |annotation |
28+ annotation . map_type_name ( &block )
29+ end
30+ when Annotations ::NodeTypeAssertion
31+ updated_annots = type_annotations . map_type_name ( &block )
32+ end
33+
34+ MethodTypeAnnotation . new ( type_annotations : updated_annots ) #: self
35+ end
36+
37+ def self . build ( leading_block , trailing_block , variables )
38+ unused_annotations = [ ] #: Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError]
39+ unused_trailing_annotation = nil #: Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
40+
41+ type_annotations = nil #: type_annotations
42+
43+ if trailing_block
44+ case annotation = trailing_block . trailing_annotation ( variables )
45+ when Annotations ::NodeTypeAssertion
46+ type_annotations = annotation
47+ else
48+ unused_trailing_annotation = annotation
49+ end
50+ end
51+
52+ if leading_block
53+ leading_block . each_paragraph ( variables ) do |paragraph |
54+ next if paragraph . is_a? ( Location )
55+
56+ if paragraph . is_a? ( CommentBlock ::AnnotationSyntaxError )
57+ unused_annotations << paragraph
58+ next
59+ end
60+
61+ case paragraph
62+ when Annotations ::MethodTypesAnnotation , Annotations ::ColonMethodTypeAnnotation
63+ type_annotations = [ ] unless type_annotations
64+ if type_annotations . is_a? ( Array )
65+ type_annotations << paragraph
66+ next
67+ end
68+ end
69+
70+ unused_annotations << paragraph
71+ end
72+ end
73+
74+ [
75+ MethodTypeAnnotation . new (
76+ type_annotations : type_annotations
77+ ) ,
78+ unused_annotations ,
79+ unused_trailing_annotation
80+ ]
81+ end
82+
83+ def empty?
84+ type_annotations . nil?
85+ end
86+ end
87+
1788 class DefMember < Base
1889 Overload = AST ::Members ::MethodDefinition ::Overload
1990
0 commit comments