class RBS::AST::Ruby::Members::MethodTypeAnnotation
Attributes
type_annotations
[R]
type_annotations
Public Class Methods
(CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol], Prism::DefNode) → [ MethodTypeAnnotation, Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError], Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil ]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 420 def self.build(leading_block, trailing_block, variables, node) unused_annotations = [] #: Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError] unused_trailing_annotation = nil #: Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil type_annotations = nil #: type_annotations return_annotation = nil #: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil param_annotations = [] #: Array[Annotations::ParamTypeAnnotation | Annotations::SplatParamTypeAnnotation | Annotations::DoubleSplatParamTypeAnnotation | Annotations::BlockParamTypeAnnotation] if trailing_block case annotation = trailing_block.trailing_annotation(variables) when Annotations::NodeTypeAssertion return_annotation = annotation else unused_trailing_annotation = annotation end end if leading_block leading_block.each_paragraph(variables) do |paragraph| next if paragraph.is_a?(Location) if paragraph.is_a?(CommentBlock::AnnotationSyntaxError) unused_annotations << paragraph next end case paragraph when Annotations::MethodTypesAnnotation, Annotations::ColonMethodTypeAnnotation type_annotations = [] unless type_annotations if type_annotations.is_a?(Array) type_annotations << paragraph next end when Annotations::ReturnTypeAnnotation unless type_annotations unless return_annotation return_annotation = paragraph next end end when Annotations::ParamTypeAnnotation, Annotations::SplatParamTypeAnnotation, Annotations::DoubleSplatParamTypeAnnotation, Annotations::BlockParamTypeAnnotation unless type_annotations param_annotations << paragraph next end end unused_annotations << paragraph end end if !type_annotations && (return_annotation || !param_annotations.empty?) doc_style, unused_params = DocStyle.build(param_annotations, return_annotation, node) type_annotations = doc_style unused_annotations.concat(unused_params) end [ MethodTypeAnnotation.new(type_annotations: type_annotations), unused_annotations, unused_trailing_annotation ] end
Returns the method type annotations from the comment block
Returns a tuple of DefAnnotations object, array of unused leading annotations, and unused trailing annotation.
(type_annotations: type_annotations) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 403 def initialize(type_annotations:) @type_annotations = type_annotations end
Public Instance Methods
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 484 def empty? type_annotations.nil? end
Returns true if it doesnβt have any annotation
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 407 def map_type_name(&block) case type_annotations when Array updated_annots = type_annotations.map do |annotation| annotation.map_type_name(&block) end when DocStyle updated_annots = type_annotations.map_type_name(&block) end MethodTypeAnnotation.new(type_annotations: updated_annots) #: self end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 524 def overloading? case type_annotations when Array type_annotations.any? do |annotation| annotation.is_a?(Annotations::MethodTypesAnnotation) && annotation.dot3_location end else false end end
() → Array[AST::Members::MethodDefinition::Overload]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 488 def overloads case type_annotations when DocStyle method_type = type_annotations.method_type [ AST::Members::MethodDefinition::Overload.new(annotations: [], method_type: method_type) ] when Array type_annotations.flat_map do |annotation| case annotation when Annotations::ColonMethodTypeAnnotation [ AST::Members::MethodDefinition::Overload.new( annotations: annotation.annotations, method_type: annotation.method_type ) ] when Annotations::MethodTypesAnnotation annotation.overloads end end when nil method_type = MethodType.new( type_params: [], type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)), block: nil, location: nil ) [ AST::Members::MethodDefinition::Overload.new(method_type: method_type, annotations: []) ] end end
Returns the method type overloads
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/members.rb, line 535 def type_fingerprint case type_annotations when DocStyle type_annotations.type_fingerprint when Array type_annotations.map(&:type_fingerprint) when nil nil end end