Class: RBS::Inline::AST::Annotations::SpecialVarTypeAnnotation

Inherits:
Base
  • Object
show all
Defined in:
lib/rbs/inline/ast/annotations.rb

Direct Known Subclasses

DoubleSplatParamType, SplatParamType

Instance Attribute Summary collapse

Attributes inherited from Base

#source, #tree

Instance Method Summary collapse

Constructor Details

#initialize(tree, source) ⇒ SpecialVarTypeAnnotation

Returns a new instance of SpecialVarTypeAnnotation.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/rbs/inline/ast/annotations.rb', line 171

def initialize(tree, source)
  @tree = tree
  @source = source

  annotation = tree.nth_tree!(1)

  if name = annotation.nth_token?(1)
    @name = name[1].to_sym
  end

  if type = annotation.nth_type?(3)
    @type = type
    @type_source = type.location&.source || raise
  else
    @type = nil
    @type_source = annotation.nth_tree!(3)&.to_s || raise
  end

  if comment = annotation.nth_tree(4)
    @comment = comment.to_s
  end
end

Instance Attribute Details

#commentObject (readonly)

: String?



166
167
168
# File 'lib/rbs/inline/ast/annotations.rb', line 166

def comment
  @comment
end

#nameObject (readonly)

: Symbol?



162
163
164
# File 'lib/rbs/inline/ast/annotations.rb', line 162

def name
  @name
end

#typeObject (readonly)

: Types::t?



164
165
166
# File 'lib/rbs/inline/ast/annotations.rb', line 164

def type
  @type
end

#type_sourceObject (readonly)

: String



168
169
170
# File 'lib/rbs/inline/ast/annotations.rb', line 168

def type_source
  @type_source
end